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>
Related
I'm getting an handshakeexception handshake error in client (os error wrong_version_number tls_record cc 242) error whenever making an http request( I also tried https ) but from only one ( Cyclist app ) of the two Flutter apps that connect to Node.js server. I'm using the same IP address and port on both, the Android tablet on which I'm testing both apps and for my machine. I checked Manifest Android/src/main/AndroidManifest.xml to see if I was using android:usesCleartextTraffic="true"`on the working app ( Shop app ) but I'm not..
What else could I check to see what's causing the error in the Cyclist app??
This is the request:
Map<String, String> headers = {
'Content-Type': 'application/json',
'api_key': Environment.dbApiKey
};
// final Uri uri = Uri.https(Environment.dbUrl, '/api/routes');
final Uri uri = Uri.http(Environment.dbUrl, '/api/routes');
await post(uri, headers: headers, body: jsonEncode(route.toMap()))
.then((resp) {
print(
'RouteMongoRepository.saveRoute response status code is: ${resp
.statusCode}, \n response is : ${jsonDecode(resp.body)}');
UserRoute saved = UserRoute.fromMap(jsonDecode(resp.body)['data']);
print('saved route to Mongo is : ${saved.toMap().toString()}');
}) .catchError((e) => print('RouteMongoRepository.saveRoute error: $e')) ;
This is the Shop app manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vinny.fixit_shop_flutter">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="io.flutter.app.FlutterApplication"
android:allowBackup="false"
android:label="fixit shop"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
and this is the Cyclist app manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name="io.flutter.app.FlutterApplication"
android:allowBackup="false"
android:label="fixit"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
</intent-filter>
</receiver>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Found it..I was missing <uses-permission android:name="android.permission.INTERNET" />in Cyclist app AndroidManifest.xml
Today I've implemented Parse.com Push service in my app.
I've noticed that the push notifications are being sent only when the app is open. I've also noticed that whenever I'm turning on my device there is a message says "Unfortunately, tof has stopped". The Logcat says Unable to start receiver.
The full Logcat:
java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2952)
at android.app.ActivityThread.access$1800(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference
at com.parse.Parse.checkContext(Parse.java:440)
at com.parse.Parse.getApplicationContext(Parse.java:270)
at com.parse.ManifestInfo.getContext(ManifestInfo.java:324)
at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:328)
at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:358)
at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:446)
at com.parse.ManifestInfo.getPushType(ManifestInfo.java:212)
at com.parse.PushService.startServiceIfRequired(PushService.java:222)
at com.parse.ParseBroadcastReceiver.onReceive(ParseBroadcastReceiver.java:19)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2945)
at android.app.ActivityThread.access$1800(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5832)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
I've tried to search on the Web but I didn't find any solution. I guess that it's something about the receiver background operation.
I need an answer as quickly as possible, so if you know a bit about Parse SDK and it's push topic so please, help me 'cause I need to solve this today.
This is my code.
MainActivity.java:
ParsePush parsePush = new ParsePush();
ParseQuery pQuery = ParseInstallation.getQuery(); // <-- Installation query
pQuery.whereEqualTo("username", User_Name);
parsePush.sendMessageInBackground(message, pQuery);
AndroidManifest.xml:
<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.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.intap.tof.permission.C2D_MESSAGE" />
<uses-permission android:name="com.intap.tof.permission.C2D_MESSAGE" />
...
<service android:name="com.parse.PushService" />
<receiver android:name="com.intap.tof.Receiver"
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>
<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.intap.tof" />
</intent-filter>
</receiver>
I also have this line on Receiver.java:
package com.intap.tof;
import android.content.Context;
import android.content.Intent;
import com.parse.ParsePushBroadcastReceiver;
public class Receiver extends ParsePushBroadcastReceiver {
#Override
public void onPushOpen(Context context, Intent intent) {
Intent i = new Intent(context, MainActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
I need major help right now!! Please help me!
Follow the steps below. This code works fine and run the receiver on background. The original answer link: https://www.parse.com/apps/quickstart#parse_push/android/native/existing
MainActivity.java file
public void onCreate() {
Parse.initialize(this, "APPLICATION ID", "CLIENT KEY");
ParseInstallation.getCurrentInstallation().saveInBackground();
}
AndroidManifest.xml file
<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.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>
<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.parse.starter" />
</intent-filter>
</receiver>
Permissions.
<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.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
Have a look at this.
public class MainApplication extends Application {
private static MainApplication instance = new MainApplication();
public MainApplication() {
instance = this;
}
public static Context getContext() {
return instance;
}
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, " ", " ");
PushService.setDefaultPushCallback(this, FabulaClient.class);
PushService.subscribe(this, "Barca", FabulaClient.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
taken from https://www.parse.com/questions/cannot-send-push-to-android-after-app-is-closed-until-screen-unlock
I've understood why I don't get the push notifications on background.
I've initialized parse sdk twice - on the OpenActivity.java and on ParseApplication.java. I've removed it from the OpenActivity.java and added this code line:
android:name=".ParseApplication"
To the application attribute on the AndroidManifest.xml and now I can get push notifications on background.
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"
....
We have been working on the integration between worklight and xtify for push notifications. We are using version 2.3.2 for xtify sdk since latest version (2.4.2) made the app failed because a class not found exception.
The logic for using xtify has been added to the native code of the WL hybrid application as follows:
public class XtifyWL extends WLDroidGap {
public static final String XTIFY_APP_KEY = "xxxxxxxx-xxxxx-xxxx-xxxxx-xxxxxxxxx";
public static final String PROJECT_NUM = "xxxxxxxxxxxx"; // This is the Google Project Number
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
XtifySDK.start(getApplicationContext(), XTIFY_APP_KEY, PROJECT_NUM);
}
We are receiving the push notifications, but they are duplicated. We received one notification for worklight that fails when you try to open it, and one more for the native application thats works correctly.
How can we fix it?
About the issue with the SDK 2.4.2.2
The exception with SDK 2.4.2.2 is:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to get provider com.xtify.sdk.db.Provider: java.lang.ClassNotFoundException: com.xtify.sdk.db.Provider
at android.app.ActivityThread.installProvider(ActivityThread.java:4609)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4236)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4178)
at android.app.ActivityThread.access$1400(ActivityThread.java:134)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4867)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.xtify.sdk.db.Provider
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.ActivityThread.installProvider(ActivityThread.java:4594)
... 12 more
The only place where we see that class is in the AndroidManifest.xml
<provider android:name="com.xtify.sdk.db.Provider" android:authorities="com.XtifyApp.XTIFY_PROVIDER" android:exported="false" />
If we comment that line it fails with the next use of any class of the SDK. We have added the sdk .jar file to the libs folder of the android project and to the build path of the android project.
Thanks,
We have found why when we send a push notification, we see them duplicated (two notifications icons on the top).
It was an error in the AndroidManifest.xml, we added all the Xtify GCM configuration and we also left the worklight GCM configuration so we where registering two receivers.
But we have still the issue of "java.lang.ClassNotFoundException" when we try to use the latest Xtify SDK. Athough at least receiving simple notifications seems to work with the SDK 2.3.2.
This is the correct AndroidManifest.xml:
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.XtifyApp" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="18"/>
<supports-screens android:smallScreens="false" android:normalScreens="true" android:largeScreens="false"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<!-- Push permissions -->
<permission android:name="com.XtifyApp.permission.C2D_MESSAGE" android:protectionLevel="signature"/>
<uses-permission android:name="com.XtifyApp.permission.C2D_MESSAGE"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="#string/app_name" android:debuggable="true" android:icon="#drawable/icon">
<activity android:name=".XtifyApp" android:label="#string/app_name" android:configChanges="orientation|keyboardHidden|screenSize" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="com.XtifyApp.XtifyApp.NOTIFICATION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="com.worklight.common.WLPreferences" android:label="Worklight Settings"></activity>
<!-- Start XTIFY -->
<provider android:name="com.xtify.sdk.db.Provider" android:authorities="com.XtifyApp.XTIFY_PROVIDER" android:exported="false" />
<receiver android:name=".XtifyNotifier" >
<intent-filter>
<action android:name="com.xtify.sdk.NOTIFIER" />
</intent-filter>
</receiver>
<receiver android:name="com.xtify.sdk.c2dm.C2DMBroadcastReceiver" >
<intent-filter android:permission="com.google.android.c2dm.permission.SEND" >
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.XtifyApp" />
</intent-filter>
<intent-filter android:permission="com.google.android.c2dm.permission.SEND" >
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.XtifyApp" />
</intent-filter>
</receiver>
<receiver android:name="com.xtify.sdk.NotifActionReceiver" />
<receiver android:name="com.xtify.sdk.wi.AlarmReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
</receiver>
<service android:name="com.xtify.sdk.location.LocationUpdateService" />
<service android:name="com.xtify.sdk.c2dm.C2DMIntentService" />
<service android:name="com.xtify.sdk.alarm.MetricsIntentService" />
<service android:name="com.xtify.sdk.alarm.TagIntentService" />
<service android:name="com.xtify.sdk.alarm.RegistrationIntentService" />
<service android:name="com.xtify.sdk.alarm.LocationIntentService" />
<!-- END XTIFY -->
<!-- Start Worklight GCM configuration -->
<!--
<service android:name=".GCMIntentService"/>
<service android:name=".ForegroundService"/>
<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"/>
<category android:name="com.XtifyApp"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
<category android:name="com.XtifyApp"/>
</intent-filter>
</receiver>
-->
<!-- END Worklight GCM configuration -->
</application>
</manifest>
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).