我正在尝试将GSM集成到我的Android应用中。我可以运行我的应用程序并通过它注册设备。
我的自定义接收方法“GCMReceiver.getGCMIntentServiceClassName”已执行,但当GCM尝试实例化我的gcm服务(TestService)时,我得到了 LogCat上的以下内容:
“无法启动服务Intent {act = com.google.android.c2dm.intent.REGISTRATION flg = 0x10 pkg = test.example.app 未找到cmp = test.example.app / com.activate.gcm.GCMIntentService“
有什么想法吗?
我的活动代码:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
GCMRegistrar.register(getApplicationContext(), "<SENDER_ID>");
Android Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="test.example.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<permission android:name="test.example.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="test.example.app.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="test.example.app.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="test.example.app.GCMReceiver" 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="test.example.app" />
</intent-filter>
</receiver>
<service android:name=".TestService" android:enabled="true" />
</application>
</manifest>
GCMReceiver类:
package test.example.app;
import android.content.Context;
import android.widget.Toast;
import com.google.android.gcm.GCMBroadcastReceiver;
public class GCMReceiver extends GCMBroadcastReceiver {
@Override
public String getGCMIntentServiceClassName(Context context) {
return "test.example.app.TestService";
}
}
TestService类:
package test.example.app;
public class TestService extends GCMBaseIntentService {
public TestService() {
super("SENDER_ID");
}
@Override
protected void onError(Context arg0, String arg1) {
}
@Override
protected void onMessage(Context arg0, Intent arg1) {
}
@Override
protected void onRegistered(Context arg0, String arg1) {
}
@Override
protected void onUnregistered(Context arg0, String arg1) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
尝试将TestService名称更改为GCMIntentService(重命名)。