Hi, I am developing small android application in which I want to integrate GCM. I used one module for it and its working fine. The only problem with it is when my application is open and if I click on notification it relaunch my application which I don't want.. What I want if application is already running then just show running window and if application is closed then launch application...
In my module code for onmessage received looks like
int icon = 0x7f020000; CharSequence tickerText = new String("Votodo: " + hashdata.get("messages")); long when = System.currentTimeMillis(); CharSequence contentTitle = "Votodo"; CharSequence contentText = new String(" " + hashdata.get("messages")); Intent notificationIntent = new Intent(this, GCMIntentService.class); Intent launcherintent = new Intent("android.intent.action.MAIN"); launcherintent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); launcherintent.setComponent(ComponentName.unflattenFromString("com.example/com.example.ExampleActivity")); launcherintent.addCategory("android.intent.category.LAUNCHER"); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launcherintent, 0); Notification notification = new Notification(icon, tickerText, when); notification.defaults = Notification.DEFAULT_ALL; notification.flags = Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(context, contentTitle, contentText,contentIntent); String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); mNotificationManager.notify(1, notification);My module is working fine if application is closed.. But relaunch application which is already running which is not expected...... Need Help..... Thank you...........
2 Answers
Hi!, i found a solution for this, but it still has a little problem wich i havent worked to reolsve yet since i was actually looking for tips to use GCM, well, in order to bring the titanium app to foreground when its already running im creating the intent as follows:
var intent = Ti.Android.createIntent({ flags: Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Titanium.Android.FLAG_ACTIVITY_CLEAR_TOP | Titanium.Android.FLAG_ACTIVITY_SINGLE_TOP, className : 'org.appcelerator.titanium.TiActivity', packageName: 'myApp.Package' });So i guess you should try using "org.appcelerator.titanium.TiActivity" instead of "com.example/com.example.ExampleActivity", and also you should look for the corresponding property to set your packageName "com.example/com.example.ExampleActivity", the problem with this is that if the app was closed due to user inactivity then the app comes to front totally blank, and stays stuck like that until the user closes it by pressing the back button.
I think there must be a better way to do this, but i havent found it yet if it exist.
Btw, can you tell me what module are you using to integrate GCM?
Sorry about the bad english anyway
Hi all, there's a new GCM module in the Marketplace called uPush for Android push messages, got it working with my project today in about 10 minutes, saved me so much time.
Your Answer
Think you can help? Login to answer this question!