每次在手机上运行应用程序都会崩溃。有什么问题吗?不幸的是“ Appname”已经停止工作了。我还尝试了其他方法来检查 Googleplay 服务,但它总是崩溃。我更新了我的谷歌播放服务,并有一个工作谷歌地图 v2完美工作。对这个代码有什么解决方案吗?它在运行安卓4.1.2和 AVD 的手机上崩溃了。
package com.example.checkgoogleplayproject;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
public class MainActivity extends Activity {
@Override
protected void onResume() {
super.onResume();
// Getting reference to TextView to show the status
TextView tvStatus = (TextView)findViewById(R.id.tv_status);
// Getting status
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
// Showing status
if(status==ConnectionResult.SUCCESS)
tvStatus.setText("Google Play Services are available");
else{
tvStatus.setText("Google Play Services are not available");
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}