我似乎有一些注册我的broadcastReceiver的问题
每当应用程序运行时,我在注册设备后获得以下错误,并获得注册ID
java.lang.RuntimeException: Unable to instantiate receiver
com.Google.androID.gcm.GCMbroadcastReceiver:
java.lang.classNotFoundException:
com.Google.androID.gcm.GCMbroadcastReceiver
这是完整的stackTrace:
解决方法 该应用程序正在寻找com.Google.androID.gcm.GCMbroadcastReceiver,但您的类位于不同的包pushNotification.GCMbroadcastReceiver中.06-19 01:08:03.994: E/AndroIDRuntime(23867): FATAL EXCEPTION: main 06-19 01:08:03.994: E/AndroIDRuntime(23867):
java.lang.RuntimeException: Unable to instantiate receiver
com.Google.androID.gcm.GCMbroadcastReceiver:
java.lang.classNotFoundException:
com.Google.androID.gcm.GCMbroadcastReceiver 06-19 01:08:03.994:
E/AndroIDRuntime(23867): at
androID.app.ActivityThread.handleReceiver(ActivityThread.java:2111)
06-19 01:08:03.994: E/AndroIDRuntime(23867): at
androID.app.ActivityThread.access$1500(ActivityThread.java:127) 06-19
01:08:03.994: E/AndroIDRuntime(23867): at
androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
06-19 01:08:03.994: E/AndroIDRuntime(23867): at
androID.os.Handler.dispatchMessage(Handler.java:99) 06-19
01:08:03.994: E/AndroIDRuntime(23867): at
androID.os.Looper.loop(Looper.java:137) 06-19 01:08:03.994:
E/AndroIDRuntime(23867): at
androID.app.ActivityThread.main(ActivityThread.java:4441) 06-19
01:08:03.994: E/AndroIDRuntime(23867): at
java.lang.reflect.Method.invokeNative(Native Method) 06-19
01:08:03.994: E/AndroIDRuntime(23867): at
java.lang.reflect.Method.invoke(Method.java:511) 06-19 01:08:03.994:
E/AndroIDRuntime(23867): at
com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-19 01:08:03.994: E/AndroIDRuntime(23867): at
com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:551) 06-19
01:08:03.994: E/AndroIDRuntime(23867): at
dalvik.system.NativeStart.main(Native Method) 06-19 01:08:03.994:
E/AndroIDRuntime(23867): Caused by: java.lang.classNotFoundException:
com.Google.androID.gcm.GCMbroadcastReceiver 06-19 01:08:03.994:
E/AndroIDRuntime(23867): at
dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-19 01:08:03.994: E/AndroIDRuntime(23867): at
java.lang.classLoader.loadClass(ClassLoader.java:501) 06-19
01:08:03.994: E/AndroIDRuntime(23867): at
java.lang.classLoader.loadClass(ClassLoader.java:461) 06-19
01:08:03.994: E/AndroIDRuntime(23867): at
androID.app.ActivityThread.handleReceiver(ActivityThread.java:2106)这是完整的清单,其中一些活动被切断了
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.gotoohlala" androID:versionCode="48" androID:versionname="4.1.2" > <uses-sdk androID:minSdkVersion="8" androID:targetSdkVersion="11" /> <uses-feature androID:name="androID.harDWare.camera" /> <supports-screens androID:smallScreens="true" androID:normalScreens="true" androID:largeScreens="true" androID:anyDensity="true" /> <application androID:harDWareAccelerated="true" androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" > <uses-library androID:name="com.Google.androID.maps" /> <!-- Push notification --> <receiver androID:name="pushNotification.GCMbroadcastReceiver" androID:permission="com.Google.androID.c2dm.permission.SEND" > <intent-filter> <action androID:name="com.Google.androID.c2dm.intent.RECEIVE" /> <category androID:name="com.gotoohlala" /> </intent-filter> </receiver> <!-- Push notification END --> <activity androID:name="launchOohlala.LaunchOohlala" androID:label="@string/app_name" androID:theme="@androID:style/theme.light.NoTitlebar" androID:screenorIEntation="portrait" androID:configChanges="orIEntation|keyboardHIDden" > <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity androID:name="launchOohlala.FakeLogin" androID:label="@string/app_name" androID:theme="@androID:style/theme.light.NoTitlebar" androID:screenorIEntation="portrait" androID:configChanges="orIEntation|keyboardHIDden" > <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.DEFAulT" /> </intent-filter> </activity> <activity androID:name="launchOohlala.CheckEmail" androID:label="@string/app_name" androID:windowsoftinputMode="stateHIDden|adjustResize" androID:theme="@androID:style/theme.light.NoTitlebar" androID:screenorIEntation="portrait" androID:configChanges="orIEntation|keyboardHIDden" > <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.DEFAulT" /> </intent-filter> </activity> <activity androID:name="discoverMyCampus.RulesFragment" androID:label="@string/app_name" androID:windowsoftinputMode="stateHIDden|adjustResize" androID:theme="@androID:style/theme.light.NoTitlebar" androID:screenorIEntation="portrait" androID:configChanges="orIEntation|keyboardHIDden" > <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.DEFAulT" /> </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="com.gotoohlala" /> </intent-filter> </receiver> <service androID:name=".GCMIntentService" /> <activity androID:name="com.facebook.LoginActivity" androID:theme="@androID:style/theme.Translucent.NoTitlebar" androID:label="@string/app_name" /> <Meta-data androID:name="com.facebook.sdk.ApplicationID" androID:value="@string/applicationID" /> <Meta-data androID:name="com.Google.androID.maps.v2.API_KEY" androID:value="AIzaSyDP2zfbRIEH0mNCkn2lpxm92DQHsfIJfPU" /> </application> <uses-permission androID:name="androID.permission.INTERNET" /> <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission androID:name="com.Google.androID.provIDers.gsf.permission.READ_GSERVICES" /> <uses-permission androID:name="androID.permission.ACCESS_COARSE_LOCATION" /> <uses-permission androID:name="androID.permission.ACCESS_FINE_LOCATION" /> <uses-permission androID:name="androID.permission.CAMERA" /> <uses-permission androID:name="androID.permission.READ_CONTACTS" /> <uses-permission androID:name="androID.permission.VIBRATE" /> <!-- Wifi related --> <uses-permission androID:name="androID.permission.INTERNET" /> <uses-permission androID:name="androID.permission.ACCESS_FINE_LOCATION" /> <uses-permission androID:name="androID.permission.ACCESS_COARSE_LOCATION"/> <uses-permission androID:name="androID.permission.SEND_SMS" /> <uses-permission androID:name="androID.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission androID:name="androID.permission.WRITE_INTERNAL_STORAGE" /> <uses-permission androID:name="androID.permission.CALL_PHONE"/> <uses-permission androID:name="androID.permission.ACCESS_NETWORK_STATE" /> <uses-permission androID:name="androID.permission.READ_CALENDAR" /> <uses-permission androID:name="androID.permission.WRITE_CALENDAR" /> <uses-permission androID:name="androID.permission.GET_ACCOUNTS" /> <uses-permission androID:name="com.gotoohlala.gcm.permission.C2D_MESSAGE" /> <permission androID:name="com.gotoohlala.permission.C2D_MESSAGE" androID:protectionLevel="signature" /> <uses-permission androID:name="com.gotoohlala.permission.C2D_MESSAGE" /> <!-- App receives GCM messages. --> <uses-permission androID:name="com.Google.androID.c2dm.permission.RECEIVE" /> <!-- 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" /> <uses-feature androID:name="androID.harDWare.telephony" androID:required="false" /> <uses-feature androID:glEsversion="0x00020000" androID:required="true"/> <permission androID:name="com.gotoohlala.permission.MAPS_RECEIVE" androID:protectionLevel="signature"/> <uses-permission androID:name="com.gotoohlala.permission.MAPS_RECEIVE"/></manifest>我的GCMbroadcastReceiver类
package pushNotification;import com.Google.androID.gms.gcm.GoogleCloudMessaging;import com.gotoohlala.OohlalaMain;import discoverMyCampus.RulesFragment;import androID.app.Activity;import androID.app.notificationmanager;import androID.app.PendingIntent;import androID.content.broadcastReceiver;import androID.content.Context;import androID.content.Intent;import androID.support.v4.app.NotificationCompat;import androID.util.Log;/** * Handling of GCM messages. */public class GCMbroadcastReceiver extends broadcastReceiver { static final String TAG = "GCMDemo"; public static final int NOTIFICATION_ID = 1; private notificationmanager mnotificationmanager; NotificationCompat.Builder builder; Context ctx; @OverrIDe public voID onReceive(Context context,Intent intent) { Log.d("SUCCESS SUCCESS","ONRECEIVE HAS BEEN CALLED,WOOT WOOT!!"); GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); Log.d("SUCCESS SUCCESS",WOOT WOOT!!"); ctx = context; String messageType = gcm.getMessageType(intent); if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + intent.getExtras().toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + intent.getExtras().toString()); } else { sendNotification("Received: " + intent.getExtras().toString()); } setResultCode(Activity.RESulT_OK); } // Put the GCM message into a notification and post it. private voID sendNotification(String msg) { mnotificationmanager = (notificationmanager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(ctx,new Intent(ctx,RulesFragment.class),0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx) .setContentTitle("GCM Notification") .setContentText(msg); mBuilder.setContentIntent(contentIntent); mnotificationmanager.notify(NOTIFICATION_ID,mBuilder.getNotification()); }}关于为什么我不能注册接收器的任何想法?
谢谢
你的应用程序包是一个不同的 – com.myAppname.
虽然您的GCMbroadcastReceiver不必与应用程序包位于同一个程序包中,但intent过滤器中的类别必须是应用程序的程序包.
你应该改变这个:
<intent-filter> <action androID:name="com.Google.androID.c2dm.intent.RECEIVE" /> <category androID:name="pushNotification" /> </intent-filter>
对此:
<intent-filter> <action androID:name="com.Google.androID.c2dm.intent.RECEIVE" /> <category androID:name="com.myAppname" /> </intent-filter>
编辑:
根据您的清单,您还有其他错误:
您指定两次广播接收器.如果您想使用自己的Receiver,则应删除此部分:
<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="com.gotoohlala" /> </intent-filter> </receiver>
另一个问题 :
删除此行:
<uses-permission androID:name="com.gotoohlala.gcm.permission.C2D_MESSAGE" />
既然你已经拥有这些行(这是正确的):
<permission androID:name="com.gotoohlala.permission.C2D_MESSAGE" androID:protectionLevel="signature" /><uses-permission androID:name="com.gotoohlala.permission.C2D_MESSAGE" />总结
以上是内存溢出为你收集整理的android – 谷歌云消息,无法初始化接收器全部内容,希望文章能够帮你解决android – 谷歌云消息,无法初始化接收器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)