java谷歌云消息开发者安卓代码崩溃
我试图用Google Cloud Messaging制作一个应用程序,我在开发者页面上遵循了实现GCMclient的所有确切步骤,代码似乎在发布时崩溃了。主活动有故障吗?或者安卓在创建应用程序时存在逻辑缺陷?我是安卓编程新手
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
package="com.iotproj.clandestine"
安卓:versionCode="1"
安卓:versionName="1.0" >
<meta-data 安卓:name="com.google.安卓.gms.version"
安卓:value="@integer/google_play_services_version" />
<uses-sdk
安卓:minSdkVersion="19"
安卓:targetSdkVersion="19" />
<uses-permission 安卓:name="安卓.permission.INTERNET" />
<uses-permission 安卓:name="安卓.permission.GET_ACCOUNTS" />
<uses-permission 安卓:name="安卓.permission.WAKE_LOCK" />
<uses-permission 安卓:name="com.google.安卓.c2dm.permission.RECEIVE" />
<application
安卓:allowBackup="true"
安卓:icon="@drawable/ic_launcher"
安卓:label="@string/app_name"
安卓:theme="@style/AppTheme" >
<activity
安卓:name="com.iotproj.clandestine.MainActivity"
安卓:label="@string/app_name" >
<intent-filter>
<action 安卓:name="安卓.intent.action.MAIN" />
<category 安卓:name="安卓.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
安卓:name="GcmBroadcastReceiver"
安卓:permission="com.google.安卓.c2dm.permission.SEND" >
<intent-filter>
<action 安卓:name="com.google.安卓.c2dm.intent.RECEIVE" />
<category 安卓:name="com.iotproj.clandestine" />
</intent-filter>
</receiver>
<service 安卓:name="GcmIntentService" />
</application>
</manifest>
public class MainActivity extends Activity {
private final static int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;TextView mDisplay;
Button mButton;
GoogleCloudMessaging gcm;
Context appContext = getApplicationContext();
// this is quite important dude
String registrationId = null;
String SENDER_ID = "xxxxxxxxx";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDisplay = (TextView) findViewById(R.id.pool);
mButton = (Button) findViewById(R.id.getid);
// Check device for Play Services APK.
if (!checkPlayServices()) {
mDisplay.setText("device not supproted !"); button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
gcm = GoogleCloudMessaging.getInstance(appContext);
try{
registrationId = gcm.register(SENDER_ID);
}
catch(IOException e){
mDisplay.setText(e.getMessage());
}
}
});
}`
# 1 楼答案
这样注册你的广播接收器
服务