0

プッシュ通知をクリックすると、アクティビティを開始しようとしています。興味深いことに、興味深いことに、アプリが閉じられていて、バックグラウンドに何もアクティビティがなく、私がプッシュを受け取ったとき、それをクリックして、必要なアクティビティを開きます。 しかし、アプリの任意のアクティビティが開かれ、プッシュを受け取ったとき、それをクリックすることは何もしません。 私はdiffの組み合わせを試みました。また、launching = trueを起動アクティビティに設定します。今Android Pushnotification、アプリ内でクリックしても何もしません

private static void showNotification(Context context,String title,String text,Intent openIntent) 
{ 


    PendingIntent pi = PendingIntent.getActivity(context, 0, openIntent, PendingIntent.FLAG_CANCEL_CURRENT|PendingIntent.FLAG_ONE_SHOT); 

    // Resources r = getResources(); 
    final Notification notification = new NotificationCompat.Builder(context) 
      .setTicker(title) 

      .setSmallIcon(R.drawable.notif_icon) 
      .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), 
        R.drawable.notif_icon)) 
      .setContentTitle(title) 
      .setContentText(text) 
      .setContentIntent(pi) 
      .setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) 
      .setAutoCancel(false) 
      .build(); 

    // also tried .setAutoCancel(true) above instead of cancel 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 


    new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      notificationManager.notify(0, notification); 
     } 
    },1000); 


} 

、私はどのような組み合わせを試してみてください:ここでは

は私のコードですか? CANCEL_CURRENTまたはFLAG_ONE_SHOTフラグを削除しますか?すでに試してみた。これらの2つのフラグがなくても、通知をクリックした結果はありませんでした。

私はアンドロイド5.1/5.0でアプリケーションを実行しています。私はこれらのアンドロイドバージョンの通知に問題があることを読んだ。だから、私はすでにandroid:exported = trueやFLAG_CANCEL currentなどのソリューションを試してみました。しかし効果はありません。

通知をクリックして目的のアクティビティを開くにはどうすればいいですか?

何か助けていただければ幸いです。 ありがとう

答えて

0

このようにFLAG_UPDATE_CURRENTを使用してください。私は

PendingIntent.getActivity(context, 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
-1
/*I tried this code on asus zenfone 2 (android 5.0), it is working without any problem please try this.*/ 
private void pushNotificationWithClickAction(String mainTittle,String subTittle,Intent intent){ 
     PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 
     Notification noti = new NotificationCompat.Builder(this) 
       .setContentTitle(mainTittle) 
       .setContentText(subTittle) 
       .setSmallIcon(R.mipmap.ic_launcher) 
       .setContentIntent(pIntent).build(); 
     noti.flags |= Notification.FLAG_AUTO_CANCEL; 
     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     notificationManager.notify(0, noti); 
    } 
+0

さて、私はそれを試してみるとそれが動作するかどうかを知るようになるため、その作業。 –

+0

私はあなたのコードを試しましたが、同じ結果です。それは1回か2回働いて、それからちょうどうまくいかない。私のコードでも同じことが起こっています。それは、アクティビティを1〜2回開き、アプリ内外に移動します。そしてもう一度ホームページに行くと、それは動作を停止します。クリックは機能しません。 しかし、今日私は、この行がプッシュをクリックして何も起こらないときにデバッグで表示されていることに気づいた: startActivityは非アクティビティコンテキストから呼び出された。 Intent.FLAG_ACTIVITY_NEW_TASK for:Intent {cmp = com.mypackage/.Activities.ChatDetailActivity –

関連する問題