运行项目时我收到了这条消息:
Unfortunately the project stopped
当我在try和catch之间添加代码时,我遇到了这个错误
application dosenot define permission com.example.elarabygroup.permission.c2d MESSAGE
我测试了所有代码,我发现错误在这里:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_elaraby_group);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
} else {
Log.v(TAG, "Already registered");
}
}
清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.elarabygroup"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ElarabyGroup"
android:label="@string/title_activity_elaraby_group" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name=".ElarabyGroup" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>
GCMIntentService类
package com.example.elarabygroup;
import com.google.android.gcm.GCMBaseIntentService;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class GCMIntenetService extends GCMBaseIntentService {
public static String TAG = "GCMIntentService";
public GCMIntenetService(String senderId) {
super(senderId);
Log.d("GCMIntentService", senderId);
}
@Override
protected void onError(Context arg0, String arg1) {
Log.d("onError", arg1);
}
@Override
protected boolean onRecoverableError(Context context, String errorId) {
Log.d("onRecoverableError", errorId);
return false;
}
@Override
protected void onMessage(Context arg0, Intent arg1) {
Log.d("onMessage", String.valueOf(arg1));
}
@Override
protected void onRegistered(Context arg0, String arg1) {
Log.d("onRegistered", arg1);
}
@Override
protected void onUnregistered(Context arg0, String arg1) {
Log.d("onUnregistered", arg1);
}
}
答案 0 :(得分:0)
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
试试这个