Push notifications behaviour while app running in background (Parse/Unity/Android) - android

I've been trying Parse's integration tutorials and examples, and I can't figure out how to make the push notifications show in tray when the app is running in background.
Notifications do appear when the app is closed, though!
Also, when in foreground, push notification events do trigger correctly.
Summing up, push notifications work perfectly except when running in background.
The notification shows in the log like this:
07-02 04:43:06.979: I/GCM(22111): GCM message com.parse.parseunitypushsample 0:1435804985959681%368c544ef9fd7ecd
07-02 04:43:07.033: W/GCM-DMM(22111): broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.parse.parseunitypushsample (has extras) }
07-02 04:43:07.041: I/ParsePushService(16145): Push notification received. Payload: {"alert":"A test push from Parse!","push_hash":"2bf06f5e2a92eab2fcb855fc1117fa33"}
07-02 04:43:07.041: I/ParsePushService(16145): Push notification is handled while the app is foregrounded.
Notice it says "foregrounded", even when some other app is in foreground. This bothers me a bit, as if Parse decided not to show the notification because it concludes that it's on foreground. Just my guess.
I'm using:
Unity 5.1.1f1 (free)
Android 5.1.1
Parse and tutorial project provided here: https://parse.com/apps/quickstart#parse_push/unity/android/new (with only modifications needed to make it run in Unity 5.x)
Provided manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.parse.parseunitypushsample" android:versionCode="1" android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<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" />
<permission android:protectionLevel="signature" android:name="com.parse.parseunitypushsample.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.parseunitypushsample.permission.C2D_MESSAGE" />
<application android:label="#string/app_name" android:icon="#drawable/app_icon">
<!-- Added "com.unity3d.player" below to avoid crash -->
<activity android:name="com.unity3d.player.UnityPlayerActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.parse.ParsePushBroadcastReceiver" 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.parse.parseunitypushsample" />
</intent-filter>
</receiver>
<service android:name="com.parse.ParsePushService" />
</application>
</manifest>
I'm just building the tutorial project, but it needs Unity upgrade, and a couple small fixes to run. Otherwise, it's clean and seems to correctly receive push notifications, but not showing them while running on background.
Is that the expected behaviour, or am I doing something wrong?
Thank you :)

If you got that, then you are almost there! I think you need to add this script to one of your GameObjects:
using UnityEngine;
using System.Collections;
using Parse;
public class ParsePushRegistration : MonoBehaviour {
// Use this for initialization
void Start () {
#if UNITY_ANDROID
ParsePush.ParsePushNotificationReceived += (sender, args) => {
AndroidJavaClass parseUnityHelper = new AndroidJavaClass ("com.parse.ParseUnityHelper");
AndroidJavaClass unityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject> ("com.unity3d.player.UnityPlayerNativeActivity");
// Call default behavior.
parseUnityHelper.CallStatic ("handleParsePushNotificationReceived", currentActivity, args.StringPayload);
};
#endif
}
}
Check and keep track of this question, it might be usefull to you:
Parse Unity Push Sample not working

Not sure if this helps, but I was able to work around this by editing the plugin source available here. To do this I simply cached the string value of the push msg in the ParsePushUnityHelper.java class and then retrieved it from Unity c# via Android CallStatic method. You can then use one of the publicly available Json modules to convert this from a json string to a dictionary. Keep in mind you'll have to recompile and link the plugin .jar to your Unity project. Good luck!

Related

Flutter: Schedule notification not working

I am developing a app using Flutter.
To show notification I an using flutter_local_notifications package.
I am getting notification, but schedule notification is not working.
Similar question was asked here How do I schedule a notification in Flutter?, but my receiver is already inside the application tag.
Here is my manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.folk.gayatrimonitor">
<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- 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. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="gayatri_monitor"
android:icon="#mipmap/ic_launcher">
<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>
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in #style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
adding this inside application of your manifest might solve your problem
<service android:name="com.folk.localnotifications.services.LocalNotificationsService"
android:exported="false" />
Remember: com.folk is used for this project only. For different project, go to your manifest, see package name and edit accordingly.
I had the same problem but couldn't find the solution online, however, later I did figure out running flutter clean then flutter run seems to do the trick for me.
You have to essentially clean your build and rebuild it again. Hope that helps.
I had the same issue, I solved it by creating a separate notification channel for each android notification I was issuing, even if they share the same priority.
In my case, I just added the following inside initState()
var initializationSettingsAndroid =
AndroidInitializationSettings('#mipmap/ic_launcher');
var initializationSettingsIOS = IOSInitializationSettings();
var initializationSettings = InitializationSettings(
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(
initializationSettings,
);

PARSE: Push Notifications "deviceToken" undefined

This is the situation in my Installation page on Parse Console:
As you see some devices have the "deviceToken" and some do not have the "deviceToken". This is not good because every device should have the deviceToken in order to work.
How is this possible? This is a serious problem because the ones that do not have the deviceToken do not receive push notifications!
I've followed all the instructions on Parse.com and implemented everything as they said, even with the help of their blank project and with the help of various questions on the web. But nothing fixed my problem and now I can't do anything.
The only thing I can think about is that before my application (it is already on the Store) used to use Google Cloud Messaging and then with this new update I've decided to change the system and use Parse removing completely GCM system. Is there maybe a conflict between the two systems?
I need to fix this as you can imagine this is a serious bug and now 3/4 of my users do not receive push notifications.
If you download the app and install it: everything is good, the deviceToken is ok. If you update the app because there already was a version with GCM on the device:
some devices register in Parse good, without any problem
some devices register in Parse but without the deviceToken
For the devices that do not have the deviceToken I've tried a lot of things: inserting a deviceToken manually, uninstall and reinstall the application, delete the specific row on Parse, etc. But nothing good... Still facing this problem.
MY CODE
Application.java
public class Application extends android.app.Application {
public Application() {
}
#Override
public void onCreate() {
super.onCreate();
// Initialize the Parse SDK.
Parse.initialize(this, "x", "x");
// Specify an Activity to handle all pushes by default.
PushService.setDefaultPushCallback(this, MainActivity.class);
}
}
MainActivity.java
In my mainActivity I just concatenate the deviceToken (in my case it is the installationId) into my userAgent: and this work fine: I always have the installationId without any problem! And this is the only thing I am doing in my MainActivity (do I need to do anything else? saveInBackground, callback, etc..?)
deviceToken = ParseInstallation.getCurrentInstallation().getInstallationId();
webSettings.setUserAgentString(userAgent + " ||" + deviceToken);
AndroidManifest.xml
<!-- Gestione del guasto-->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Utilizzo di internet -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permesso di vibrare per le push notifications -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Mantiene attivo il processore così da poter ricevere in qualsiasi momento le notifiche -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Consente di impostare l'allarme per l'aggiornamento automatico -->
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<permission android:name="com.hoxell.hoxellbrowser.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.hoxell.hoxellbrowser.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:name="com.hoxell.hoxellbrowser.Application"
android:allowBackup="true"
android:icon="#drawable/ic_launcher_hoxell"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<!-- Richiesto per le applicazioni che usano Google Play Services -->
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SettingsActivity"></activity>
<receiver android:name=".AlarmReceiver"/>
<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.hoxell.hoxellbrowser.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" />
<category android:name="com.hoxell.hoxellbrowser" />
</intent-filter>
</receiver>
</application>
Build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:support-v4:20.+' //support
compile "com.google.android.gms:play-services:5.0.+" //play services
compile 'com.parse.bolts:bolts-android:1.+'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
}
I don't really know what else to do, that's why I hope that somebody can help me with this.
Thank you.
Are you using 2 user profiles at the same time on the tablet? Because I've had exactly the same problem and from my experience there is a conflict between the profiles. Infact, in my situation one device was registering 2 rows into the Parse database. One with the deviceToken and one with "undefined" deviceToken.
Unfortunately I've never solved this problem, I guess this is a bug from Parse.
It could be useful to set parse logging to verbose to help debug further:
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
With that I noticed that I was using the wrong "sender_id" in my manifest:
<meta-data android:name="com.parse.push.gcm_sender_id"
android:value="id:123456789"/>
That might not be the exact solution, but LOG_LEVEL_VERBOSE might help debug this.
Some installations do have a GCM Registration Id set up in their deviceToken column, which is a good indication that your setup is correct. Is it definitely possible for an installation to lack a GCM Registration Id:
The device may not have access to Google Services Framework (e.g. Amazon Kindle Fire). If you have set up the non-GCM ParsePush receiver, pushes to these devices should still get delivered.
The app has been deleted from the device, and thus it has been unregistered from GCM. We do not automatically delete installations in this case as that could potentially lead to unintended data loss, given that you're allowed to store arbitrary data in your installation class.
Google Services Framework may have been unavailable when the device attempted to register itself.
In the first two scenarios, this is working as expected and it's not something to generally worry about.
Are those simulator users? From my experience if you are running an installation on your simulator it does not auto setup the device token.
I had been struggling with this problem for a long time until I recently realized what has been going on. Not only does the package name need to match, but you also need to include the build flavor in your declaration.
If you followed the parse tutorial and replace com.parse.starter with your package name, you are done if you have no build flavor, but if you do you need to make sure to include that as such:
com.packagename.build_flavor{debug, release, etc.}
You may create a class and extends Application to initialize your app. Such that initialize ParsePush and updateParseInstallation.
Sample code:
public class YourappApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this,YOU_PARSE_applicationId, YOU_PARSE_clientKey);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}
public static void updateParseInstallation(ParseUser user) {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("userId", user.getObjectId());
installation.saveInBackground();
}
}
And then in your LoginActivity: updateParseInstallation
ParseUser.logInInBackground(username, password, new LogInCallback() {
#Override
public void done(ParseUser parseUser, ParseException e) {
setProgressBarIndeterminateVisibility(false);
if(e == null){
YourappApplication.updateParseInstallation(parseUser);
Intent intent = new Intent(LoginActivity.this,
MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
}
});
I had similar issue after renaming module.
Try 'Clean Project' followed by 'Rebuild Project'
I had this problem but in a cordova app using the phonegap-parse-plugin. I had to edit the android java code in the plugin to fix, so effectively the same.
Try adding this save BETWEEN the Initialize and the setDefaultPushCallback:
ParseInstallation.getCurrentInstallation().save();
It has to be between them to work.
My problem was that I was missing this permission in the manifest:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
Also I had to add meta-data just before
<service android:name="com.parse.PushService" />:
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="YourParseApplicationID" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="YourParseClientKey" />
Now check if you can get the deviceToken. Also check your app dashboard in Parse if everything is ok.
I dont know if tghis helps anyone but I was able to get the device token and notification correctly after removing this line from my Application Class containing parse intalation. here is the code. the commented line (removed line) made everything work properly. Can anyone explain why this works?
package com.test.android.push;
import android.app.Application;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
public class FarrApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this, "xxxx", "xxxx");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("---"); // REMOVED AND WORKS

IntentReceiver not called with Android Versions < 4.1

I am using Android Studio. I implemented an push service in my app. It is working with all kind of devices with newer Android versions, however it won't work with an Galaxy S2 Mini with Android 2.3.6.
The device receives pushs from other apps with Urban Airship libraries.
Relevant parts of the Manifest:
<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.my_app.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.my_app.app.permission.C2D_MESSAGE" />
<receiver
android:name=".IntentReceiver"
android:permission="com.google.android.c2dm.permission.SEND"
>
<intent-filter
android:priority="100">
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.C2D_MESSAGE" />
<category android:name="com.my_app.app" />
</intent-filter>
</receiver>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<service android:name=".GCMIntentService"
android:enabled="true"/>
IntentReceiver.java:
import android.support.v4.content.WakefulBroadcastReceiver;
public class IntentReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
//doing some stuff & starting my service here,
//never gets called with said device
}
}
The device gets registered with push. I have to call it twice before the id is returned, but the right Id is saved in my backend (I send the push manually anyways, so that shouldn't be the issue). I also register a second receiver from code when the app is in foreground, but none of them gets called.
If I add <uses-permission android:name="android.permission.C2D_MESSAGE" /> in my Manifest, I receive an com.google.android.c2dm.intent.REGISTRATION action when I send a push.
I had the same issue with an Galaxy Tab. Before updating it received a "com.google.android.c2dm.intent.REGISTRATION" with every push (with intent.getStringExtra("unregistered") set). So instead of getting RECEIVE it just was unregistered, just like the Galaxy Mini. I then updated it to 4.2.2. It now gets a RECEIVE every push like it should.
I rarely read about this very problem (not receiving pushs with < 4.1). But I didn't find a solution.
I wonder if anyone experienced something similar and found a solution or if somebody sees a problem with my manifest.
So, apparently not all package names in the manifest are replaced by build.gradle. In my case (with Android Studio 0.8) it was the custom permission that was wrong. I am using flavours, I guess I should have mentioned that. The package name in the custom permission has to be the package name including flavour, like this:
<permission
android:name="com.my_app.app.myflavour.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.my_app.app.myflavour.permission.C2D_MESSAGE" />

App refuses to connect to Parse backend

I am working on an app called TobaccoRoad that uses a library project called BestApproach. It uses a Parse backend to display custom generated content and handle push notifications. Everything was working pretty alright until a few days ago, when I must have messed up some settings somewhere and it no longer seems to be making the connection to the parse systems. I'm quite sure it's a local issue, because my second tester phone, which has not had updated code pushed to it in a few days, is still receiving notifications and can view that custom content.
The weird thing is, even after clearing my workspace and starting fresh from the (definitely good) code my employer gave me, and following all the tutorials and troubleshooting guides on Parse.com (see https://parse.com/docs/push_guide#installations/Android; https://parse.com/tutorials/android-push-notifications) I'm still not connecting to Parse. I haven't made any significant changes that I can recall, so I'm at a loss as to what might be causing this.
I know it's not an issue of a bad applicationID or clientKey, because even substituting random strings into the Parse.initialize call gave the same results, and a logcat error about not being able to authenticate.
Here are the relevant bits from my manifest files, first for the library project...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bestapproach.lib"
android:versionCode="8"
android:versionName="1.6.1">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name"
android:theme="#style/Theme.BA" >
<activity android:name="com.bestapproach.lib.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation"
android:theme="#style/Theme.BA.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--Declarations for all of my Activities...-->
<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>
</application>
</manifest>
And the manifest is exactly the same for my dependent project, with the exception of where I define a custom receiver at the end:
<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.bestapproach.lib.MyCustomReceiver">
<intent-filter>
<action android:name="com.bestapproach.lib.UPDATE_STATUS" />
</intent-filter>
</receiver>
And here's the code for the onCreate() method in my main activity (SplashActivity) where the Parse service is initialized:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
String parseClientId = getString(R.string.parse_client_id);
String parseAppId = getString(R.string.parse_app_id);
//debug output
Log.v("parse should be initializing...", parseAppId+" "+parseClientId);
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(this, parseAppId, parseClientId);
PushService.subscribe(this, "", MenuActivity.class);
PushService.setDefaultPushCallback(this, SplashActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseAnalytics.trackAppOpened(getIntent());
final Activity a = this;
// Fetches content if it doesn't exist.
StoreManager sm = StoreManager.getInstance(a);
ParseStoreManager psm = ParseStoreManager.getInstance(a);
return;
}
}
Suggestions I've found that seem like they may be on track with what I need include running Parse.initialize() in the onCreate() of every activity, which I don't really want to do as there are a lot of them and that would be a lot of duplicated code, or generating an Application object and running it from there. Everything I've tried in relation to that has ended up breaking once I add it to my manifest file, due to TobaccoRoad's dependencies on the library project.
I know, it's a lot to dig through, but any suggestions would be appreciated. Thanks everybody.
Possible fix:
Change this line
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(this, parseAppId, parseClientId);
to this:
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(SplashActivity.this, parseAppId, parseClientId);
the issue is that
ParseAnalytics.trackAppOpened(getIntent());
accepts the intent from that activity from your SplashActivity and from the application scope
Also, you initialize parse from the activity which we generally don't do.
We try initialize parse from the Application class so it has the context of the Application scope and not of the Activity Scope.
I recommend you to create an Application class and include the parse code in the onCreate of the Application...which you would need to do only once.
Or, you can create some BaseActivities and make all your activities in the application extend to that. This will save you from writing duplicate code...this is just in case you are bound not to create an Application class.
Pardon me for anything wrong...I am new in answering.

GCM Android: onRegistered() not being called

I'm having a problem with GCM on Android. It fails to execute the onRegistered() callback, or ever return a good regId, on one of my test devices (Droid2) - but it works perfectly well on another device (Galaxy Nexus).
I'm following the basic example here. The caller looks like this:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals(""))
GCMRegistrar.register(this, Constants.SENDER_ID);
else
Log.v(TAG, "Already registered");
And my manifest has this:
<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" />
and
<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.gcl.myapp" />
</intent-filter>
</receiver>
Why isn't the onRegistered() callback working? And what could be causing it to work on one device, but fail on another?? Thanks.
If it works on some devices but not others then it is to do with one of the following:
Pre Android 4.0.4 the device requires a valid google account to work.
GCM only works on devices with Play Store App and API 8 onwards.
Your manifest is badly formatted - use Lint to check!
Device/App is already registered, the Play implementation may not return again.. Try GCMRegistrar.unregister(this); first.
Hope that helps!
I had the same problem. If you are using AngularJS + IonicFramework you do not have to do this:
After you create your factory with your onDeviceReady function, creates onNotificationGCM function. Something like this:
app.factory('PushProcessingService', function () {
..
});
function onNotificationGCM(e) {
}
I was creating onNotificationGCM inside my factory. This solve my problem.

Categories

Resources