0

我正在开发一个钛应用程序,其中包括谷歌云消息。我能够从服务器获得注册ID。另外,当我的应用程序正在运行时,我能够从我的服务器接收消息。但是当我的应用程序在后台运行时,我的应用程序能够接收消息。但是当我点击通知时,它不会恢复我的应用程序。我在我的app.js中添加了以下代码:无法在android中收到推送通知后恢复应用程序

var intent = Titanium.Android.createIntent({ 
    action: Titanium.Android.ACTION_MAIN, 
    className: 'com.nrcomps.rtlireportsandroid.RtlIreportsAndroidActivity', 
    packageName: 'com.nrcomps.rtlireportsandroid',  
    flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP | 
    Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_NEW_TASK  
}); 
intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER); 
var pending = Ti.Android.createPendingIntent({ 
    activity : Ti.Android.currentActivity, 
    intent : intent, 
    type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY, 
    flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK 
}); 

任何帮助,将不胜感激。

感谢

+0

@Sonal,请不要在帖子中添加签名。请在你的个人资料中更新你的名字。堆栈溢出有一个非常漂亮的签名,在你的每篇文章的右下角的蓝色矩形中。 –

+0

我不会有钛的想法.. PLZ尝试通过删除标志:Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP | Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_NEW_TASK --------------- and ------- ype:Ti.Android.PENDING_INTENT_FOR_ACTIVITY, flags:Ti.Android.FLAG_ACTIVITY_NEW_TASK – Sandy09

+0

我已将全部标志。但它仍然不起作用。 – user859177

回答

0

您需要设置在IntentIntent标志。您在电话中指定他们以获得PendingIntent

notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
    Intent.FLAG_ACTIVITY_SINGLE_TOP | 
    Intent.FLAG_ACTIVITY_NEW_TASK); 
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
    notificationIntent, 0); 
+0

感谢您的快速回复。我已经添加了您提供的代码,但仍然无法使用。 – user859177

0
String st = "message"; 
     NotificationManager notifymanManager = (NotificationManager) getSystemService(ns); 
     int s = R.drawable.icon; 

     long when = System.currentTimeMillis(); 
     Notification nt = new Notification(s, st, when); 
     Intent intent1 = new Intent(this, Woobme.class); 
     intent1.addCategory(Intent.CATEGORY_LAUNCHER); 
     intent1.setAction(Intent.ACTION_MAIN); 
      nt.flags = Notification.FLAG_AUTO_CANCEL; 
     PendingIntent pd = PendingIntent.getActivity(this, 0, intent1, 0); 
     nt.setLatestEventInfo(context, st, st, pd); 
     int i = 1; 
     int hello_id = i; 
     long m[] = { 0, 100, 200, 200 }; 
     nt.defaults |= Notification.DEFAULT_SOUND; 
     nt.vibrate = m; 

     notifymanManager.notify(hello_id, nt); 
+0

intent1.addCategory(Intent.CATEGORY_LAUNCHER); intent1.setAction(Intent.ACTION_MAIN);这些行重新启动旧的活动,它对我来说工作得很好......你可以发布你的代码吗? – Sandy09

+0

请找到更新后的问题。谢谢 – user859177

+0

我仍然面临同样的问题。我正在开发这个应用程序在钛和使用Java应用程序发送通知。它成功发送消息,但是当应用程序在后台时,它不会启动应用程序。如果它在前景中,它可以正常工作。如果我使用我的钛应用程序发送通知,那么它会正常启动应用程序。是否有任何问题通过不同的应用程序发送通知(即在Java中)?任何帮助将不胜感激。谢谢 – user859177

相关问题