Hello I want to implement Google's GCM into my android application.
I linked to google play services lib
I wrote the following permissions :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.torasecurity.mobile.alarm.RECEIVE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.torasecurity.mobile.alarm.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.torasecurity.mobile.alarm.C2D_MESSAGE" />
A simple broadcast receiver:
<receiver android:name=".MyReceiver" android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="YOUR_PACKAGE_NAME" />
</intent-filter>
</receiver>
But I get this stack trace when trying to register:
08-07 11:43:12.806: W/System.err(19067): java.io.IOException: MAIN_THREAD
08-07 11:43:12.826: W/System.err(19067): at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
08-07 11:43:12.826: W/System.err(19067): at com.torasecurity.mobile.alarm.SplashScreen.register(SplashScreen.java:27)
08-07 11:43:12.826: W/System.err(19067): at com.torasecurity.mobile.alarm.SplashScreen.onCreate(SplashScreen.java:56)
08-07 11:43:12.826: W/System.err(19067): at android.app.Activity.performCreate(Activity.java:5206)
08-07 11:43:12.826: W/System.err(19067): at
Does any body know what I am doing wrong ?
Most probably you are trying to register to GCM directly from the activity.
But the register() method accesses the network, and like any other method that performs network operations, it should run in a separate thread otherwise an exception is thrown.
The solution is to put the registration to GCM in a thread, for example in a AsyncTask, like in docs. (registerBackground() method).
Related
starting on android P my app is not able to register for a GCM ID. My PushManager code looks like
try
{
GcmClient.CheckDevice(context);
GcmClient.CheckManifest(context);
String[] senderIds = GcmBroadcastReceiver.SENDER_IDS;
foreach (String id in senderIds)
{
System.Diagnostics.Debug.WriteLine("sender id = " + id);
}
GcmClient.Register(context, senderIds);
if (GcmClient.IsRegistered(context))
{
System.Diagnostics.Debug.WriteLine("push registration successfull: " +
GcmClient.GetRegistrationId(context));
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("push registration failed: " + e.Message.ToString());
}
My manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.app" android:versionName="1.8.5" android:versionCode="97">
<uses-sdk android:minSdkVersion="16" />
<application android:label="My app" android:icon="#mipmap/icon" android:theme="#style/Theme.App" android:hardwareAccelerated="true" android:windowSoftInputMode="stateHidden|adjustResize" android:name="android.support.multidex.MultiDexApplication">
<activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="#android:style/Theme.Translucent" />
</application>
<permission android:name="com.rotogrinders.rg_lineups.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.rotogrinders.rg_lineups.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<permission android:name="android.permission.STATUS_BAR_SERVICE" android:protectionLevel="signature" />
<!-- For Google Play Services -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.REGISTER" />
<service android:name="com.google.android.gms.analytics.AnalyticsService" android:enabled="true" android:exported="false" />
Whenever I try to register or unregister i get this error:
07-05 16:35:49.156 W/ActivityManager( 1167): Unable to start service Intent { act=com.google.android.c2dm.intent.UNREGISTER pkg=com.google.android.gsf (has extras) } U=0: not found
07-05 16:35:49.169 W/ActivityManager( 1167): Unable to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } U=0: not found
I've found that devices running older OSs register fine. the only issue I've had with this so far is with the android P preview. Any help would be appreciated.
You are likely be using an older version of GCM.
You may upgrade to GCM 11 or higher, or even better, migrate to FCM. (GCM is now deprecated)
(The latest GCM version is 15.0.1: com.google.android.gms:play-services-gcm:15.0.1)
The problem is when I call ParsePush.subscribeInBackground method I get an error:
Parse subscription error: bad json response: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
Example code attached below:
Parse.initialize(AnUtility.GetApplicationContex(), appId, dotNetKey);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d(TAG, "Successfully subscribed to Parse broadcast Push Notifications");
} else {
Log.e(TAG, "Parse subscription error: " + e.getMessage());
}
}
});
There are some warnings in LogCat according to this issue:
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): Cannot use GCM for push because the app manifest is missing some required declarations. Please make sure that these permissions are declared as children of the root <manifest> element:
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <uses-permission android:name="android.permission.INTERNET" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <uses-permission android:name="android.permission.VIBRATE" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <uses-permission android:name="android.permission.WAKE_LOCK" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <uses-permission android:name="android.permission.GET_ACCOUNTS" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <permission android:name="com.myappbundle.permission.C2D_MESSAGE" android:protectionLevel="signature" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <uses-permission android:name="com.myappbundle.permission.C2D_MESSAGE" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): Also, please make sure that these services and broadcast receivers are declared as children of the <application> element:
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <service android:name="com.parse.PushService" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <intent-filter>
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <action android:name="com.google.android.c2dm.intent.RECEIVE" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): <category android:name="com.myappbundle" />
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): </intent-filter>
01-25 14:21:46.057: E/com.parse.ManifestInfo(3217): </receiver>
My AndroidManifest.xml file contains next receivers:
<receiver android:exported="true" android:name="com.androidnative.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.unionassets.android.plugin.preview" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
and permissions:
<permission android:name="com.example.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<permission android:name="com.unionassets.android.plugin.preview.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="com.unionassets.android.plugin.preview.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
I'am using Parse Android SDK 1.8.2 for now. In eralier 1.8.0 version same code worked well.
So, does it depends on Parse SDK version or there is something else in my code?
Looking forward for advice.
Thanks in advance.
Best regards,
Alex.
I have just had a very similar issue.
The solution (it turns out) was simple, but it was really nasty to track down:
The Application Id key was wrong!
I got the key from a colleague, and it turn out that one of us had chopped the first character while copying it :-(
Why Parse reported this as:
Parse subscription error: bad json response: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
seems totally counter-intuitive. I wish they'd made another exception, or at least returned an actual JSON string that can be seen by the developer, so the issue can be recognized as an initialization error, and not a parsing issue.
Double-check your keys and see if that solves the problem - as it did for me.
I'm using https://github.com/kobakei/unity-gcm for GCM notifications in Unity3D. I receive the messages on the device. When I tap on the notification nothing happens. I expect the application to start. This is the log:
V/GCMRegistrar( 8441): Setting the name of retry receiver class tocom.kskkbys.unitygcmplugin.UnityGCMBroadcastReceiver
V/UnityGCMBroadcastReceiver( 8441): getGCMIntentServcieClassName
V/GCMBroadcastReceiver( 8441): GCM IntentService class: com.kskkbys.unitygcmplugin.UnityGCMIntentService
V/GCMBaseIntentService( 8441): Acquiring wakelock
D/ConnectivityService( 845): handleInetConditionHoldEnd: net=0, condition=100, published condition=100
V/GCMBaseIntentService( 8441): Intent service name: GCMIntentService-DynamicSenderIds-1
D/STATUSBAR-NetworkController( 1051): onReceive() - CONNECTIVITY_ACTION, INET_CONDITION_ACTION
V/UnityGCMIntentService( 8441): onMessage
V/UnityGCMIntentService( 8441): ticker: ticker
D/STATUSBAR-NetworkController( 1051): getUpdateDataNetType() - mDataNetType:15
D/STATUSBAR-NetworkController( 1051): updateDataNetType()
D/STATUSBAR-NetworkController( 1051): Nothing, mRoamingIconId = 0
V/UnityGCMIntentService( 8441): foo: bar
V/UnityGCMIntentService( 8441): from: xxxxx
V/UnityGCMIntentService( 8441): content_title: New Friend Request
V/UnityGCMIntentService( 8441): score: 123
V/UnityGCMIntentService( 8441): is_first: true
V/UnityGCMIntentService( 8441): content_text: test
V/UnityGCMIntentService( 8441): collapse_key: do_not_collapse
D/dalvikvm( 8441): Trying to load lib /data/app-lib/com.company.app-23/libmain.so 0x42587730
D/dalvikvm( 8441): Added shared lib /data/app-lib/com.company.app-23/libmain.so 0x42587730
W/dalvikvm( 8441): No implementation found for native Lcom/unity3d/player/UnityPlayer;.UnitySendMessage:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
W/System.err( 8441): java.lang.UnsatisfiedLinkError: Native method not found: com.unity3d.player.UnityPlayer.UnitySendMessage:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
W/System.err( 8441): at com.unity3d.player.UnityPlayer.UnitySendMessage(Native Method)
W/System.err( 8441): at com.kskkbys.unitygcmplugin.Util.sendMessage(Util.java:23)
W/System.err( 8441): at com.kskkbys.unitygcmplugin.UnityGCMIntentService.onMessage(UnityGCMIntentService.java:50)
W/System.err( 8441): at com.google.android.gcm.GCMBaseIntentService.onHandleIntent(GCMBaseIntentService.java:223)
W/System.err( 8441): at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
W/System.err( 8441): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 8441): at android.os.Looper.loop(Looper.java:136)
W/System.err( 8441): at android.os.HandlerThread.run(HandlerThread.java:61)
V/UnityGCMNotificationManager( 8441): showNotification
V/GCMBaseIntentService( 8441): Releasing wakelock
W/ContextImpl( 845): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1505 com.android.server.StatusBarManagerService.sendNotification:985 com.android.server.StatusBarManagerService.addNotification:674 com.android.server.NotificationManagerService$7.run:2157 android.os.Handler.handleCallback:733
and
W/ContextImpl( 845): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1505 com.android.server.StatusBarManagerService.sendNotification:985 com.android.server.StatusBarManagerService.removeNotification:710 com.android.server.NotificationManagerService.cancelNotificationLocked:2469 com.android.server.NotificationManagerService.access$5100:162
D/STATUSBAR-StatusBarManagerService( 845): sendNotification(3) - 1
EDIT:
AndroidManifest.xml:
<!-- Android GCM Plugin -->
<receiver android:name="com.kskkbys.unitygcmplugin.UnityGCMBroadcastReceiver" 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.company.application" />
</intent-filter>
</receiver>
<service android:name="com.kskkbys.unitygcmplugin.UnityGCMIntentService" />
<!-- Android GCM Plugin -->
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Android GCM Plugin -->
<permission android:name="com.company.application.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.company.application.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.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Android GCM Plugin -->
EDIT2:
This is the error that comes up in logcat when I touch the notification icon and expect the app to start.
Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1505 com.android.server.StatusBarManagerService.sendNotification:985 com.android.server.StatusBarManagerService.removeNotification:710 com.android.server.NotificationManagerService.cancelNotificationLocked:2469 com.android.server.NotificationManagerService.access$5100:162
Viewing your logcat it looks as if your NotificationListenerService is not working as it is expected to work. As you have not provided code, you may try out these probable solutions in order to make sure that the received broadcast is properly handled as notification and the tap on notification opens the relevant activity.
There may be a kind of conflict on your device. The best way to deal with this is to clean up some space and re-install the app from the Google Play.
Use below function instead of sendBroadcast(Intent intent).
void sendBroadcastAsUser(Intent intent, UserHandle user)
for example,
context.sendBroadcastAsUser(newIntent, new UserHandle(UserHandle.USER_CURRENT));
Make sure you have proper permissions in your app manifest file.
<manifest package="com.example.gcm" ...>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<application ...>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gcm" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
</application>
</manifest>
Follow the instructions in this document to know more about the client implementation.
Hope this would Help!!
The logcat errors in the question don't have anything to do with the app not starting from the notification.
The problem was solved by LeshM # https://github.com/kobakei/unity-gcm/issues/1
I found out that the gcm plugin is setting a specific unity activity as the pending intent of the notification.
As soon as I added the activity to my AndroidManifest.xml it worked!
These are the activities I defined:
<activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
android:launchMode="singleTask"
android:label="#string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:launchMode="singleTask"
android:label="#string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
</activity>
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
android:launchMode="singleTask"
android:label="#string/app_name"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
<meta-data android:name="android.app.lib_name" android:value="unity" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
There was no problem while running my little android application. I integrated my application new feature. I am using real time push notification with using ready script by www.parse.com . There is no problem while running but when i closed screen and reopen .There is an error. Your application closed unexpectedly. I dont know why and there is no log.
I am using this code in my main activity before oncreate
Parse.initialize(this, "XXX", "YYY");
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseAnalytics.trackAppOpened(getIntent());
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.islamiceducationquestions.v1"
android:versionCode="13"
android:versionName="8.0.1">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission android:protectionLevel="signature"
android:name="com.islamiceducationquestions.v1.permission.C2D_MESSAGE" />
<uses-permission android:name="com.islamiceducationquestions.v1.permission.C2D_MESSAGE" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:theme="#android:style/Theme.Holo.Light.DarkActionBar">
<activity
android:name=".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>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.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" />
<!--
IMPORTANT: Change "com.parse.starter" to match your app's package name.
-->
<category android:name="com.islamiceducationquestions.v1" />
</intent-filter>
</receiver>
</application>
</manifest>
Log is :
java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2844)
at android.app.ActivityThread.access$1700(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1440)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
at com.parse.Parse.checkContext(Parse.java:583)
at com.parse.Parse.getApplicationContext(Parse.java:191)
at com.parse.ManifestInfo.getContext(ManifestInfo.java:241)
at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:249)
at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:272)
at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:357)
at com.parse.ManifestInfo.getPushType(ManifestInfo.java:129)
at com.parse.PushService.startServiceIfRequired(PushService.java:150)
at com.parse.ParseBroadcastReceiver.onReceive(ParseBroadcastReceiver.java:19)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2833)
... 10 more
As you can see here Android Parse.com Simple ListView Tutorial you will need to call Parse.initialize from Application's onCreate instead of from Activity or Service. do it as:
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Add your initialization code here
Parse.initialize(this, YOUR_APPLICATION_ID, YOUR_CLIENT_KEY);
}
}
Also add ParseApplication in AndroidManifest.xml as application tag name:
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
android:name="ParseApplication"
....
This seems to be a fairly common question without a good answer. I've just followed the google guide for GCM push messaging and am getting this error:
E/AndroidRuntime(21779): java.lang.RuntimeException: Unable to start activity ComponentInfo{eric.bander.app/eric.bander.app.MenuScreen}: java.lang.IllegalStateException: Application does not define permission eric.bander.app.permission.C2D_MESSAGE
E/AndroidRuntime(21779): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
E/AndroidRuntime(21779): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
E/AndroidRuntime(21779): at android.app.ActivityThread.access$600(ActivityThread.java:127)
E/AndroidRuntime(21779): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
E/AndroidRuntime(21779): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(21779): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(21779): at android.app.ActivityThread.main(ActivityThread.java:4507)
E/AndroidRuntime(21779): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(21779): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(21779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:978)
E/AndroidRuntime(21779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
E/AndroidRuntime(21779): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(21779): Caused by: java.lang.IllegalStateException: Application does not define permission eric.bander.app.permission.C2D_MESSAGE
E/AndroidRuntime(21779): at com.google.android.gcm.GCMRegistrar.checkManifest(GCMRegistrar.java:137)
E/AndroidRuntime(21779): at eric.bander.app.MenuScreen.onCreate(MenuScreen.java:43)
E/AndroidRuntime(21779): at android.app.Activity.performCreate(Activity.java:4469)
E/AndroidRuntime(21779): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
E/AndroidRuntime(21779): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
Here is my manifest file:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="eric.bander.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="eric.bander.app.permission.C2D_MESSAGE" />
<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="eric.bander.app" />
</intent-filter>
</receiver>
This is the piece of code in MainMenu:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "808426403545");
} else {
Toast.makeText(this, GCMRegistrar.getRegistrationId(this), Toast.LENGTH_LONG).show();
}
And I don't know if its relevant but my app strucutre is like this with the GCM intent service in another package:
eric.bander
-MainMenu.class
eric.bander.misc
-GCMIntentService.class
I hope someone can help with this, always frustrating when you are following a tutorial.
TIA
My error was having GCMIntentService in a different package to the class that registered the GCM.