4

Androidでローカル通知を実装していて、Android 6.0(Samsung S7)に表示されないという問題があります。 解決策を探していましたが、この問題のために何かを見つけることはできません。Androidの通知がAndroid 6.0(Marshmallow)で動作しない

Context acontext = getApplicationContext(); 

    PackageManager pm = acontext.getPackageManager(); 
    Intent notificationIntent = pm.getLaunchIntentForPackage(acontext.getPackageName()); 
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    PendingIntent pendingIntent = PendingIntent.getActivity(acontext, 0, notificationIntent, 0); 
    int notification_icon = acontext.getResources().getIdentifier("icon", "drawable", acontext.getPackageName()); 
    int notificationID = 0; 

    // Build notification 
    Notification noti = new Notification.Builder(acontext) 
      .setContentTitle("Title") 
      .setContentText("Incoming text") 
      .setSmallIcon(notification_icon) 
      .setContentIntent(pendingIntent) 
      .setLights(Color.RED, 1, 1) 
      .build(); 
    NotificationManager notificationManager = (NotificationManager) acontext.getSystemService(Context.NOTIFICATION_SERVICE); 
    // hide the notification after its selected 
    noti.sound = Uri.parse("android.resource://" + acontext.getPackageName() + "/raw/incoming"); 
    noti.flags |= Notification.FLAG_AUTO_CANCEL; 
    notificationManager.notify(notificationID, noti); 

でした誰:私も、私は通知のタイトル、テキスト、着信音(生フォルダ)に定義されている、適切な解像度/描画可能なフォルダのアイコンを持っていますが、それは現れていない... は私のコードがありますそうでなければこの問題が発生しますか?どんな助けもありがとう。ありがとうございました。

+2

通知は下位バージョンで機能していますか? –

+0

はい、Android 5.0で動作しています –

+0

ロガーにメッセージが表示されますか? –

答えて

0

Android搭載端末でプッシュ通知を受け取るには、Google Playサービスを有効にする必要があります。 Google Playサービスが有効になっており、一般的なトラブルシューティングの手順で問題を解決できない場合は、アプリをリセットする必要があります。アプリをリセットするには、「設定」→「アプリ」→「PagerDuty」に移動し、「データを消去」をタップします。

Android 6.0以降では、アプリが優先モードで優先アプリとして設定されていることを確認してください。

Android 6.0以降では、アプリケーションがDozeモードで消音されているかどうかを確認してください。

+0

Playサービスが有効になっています。また、他のアプリ(GmailやFacebookなど)からプッシュ通知を受け取りました。アプリの通知のみが表示されません。 –

0

はそれに応じて> 6.0とother.For 6.0私たちは白い背景のアイコンを必要とするバージョンのアイコンを設定するアンドロイドのバージョンを確認してください。

if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { 
icon = R.mipmap.your_logo_for_Lolipop; 
}else{ 
icon = R.drawable.your_logo_for_Kitkat ; 
} 
1

新しい通知にはいくつかの変更があります。新しいNotificationCompat.Builder(this)は廃止され、上記のアンドロイド・オレオの場合はNotificationChannelが必要です。このソリューションを試すことができます。

NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(mContext.getApplicationContext(), "notify_001"); 
     Intent ii = new Intent(mContext.getApplicationContext(), RootActivity.class); 
     PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, ii, 0); 

     NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle(); 
     bigText.bigText(verseurl); 
     bigText.setBigContentTitle("Title"); 
     bigText.setSummaryText("Text in detail"); 

     mBuilder.setContentIntent(pendingIntent); 
     mBuilder.setSmallIcon(R.mipmap.ic_launcher_round); 
     mBuilder.setContentTitle("Your Title"); 
     mBuilder.setContentText("Your text"); 
     mBuilder.setPriority(Notification.PRIORITY_MAX); 
     mBuilder.setStyle(bigText); 

     NotificationManager mNotificationManager = 
       (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); 


     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
      NotificationChannel channel = new NotificationChannel("notify_001", 
        "Channel human readable title", 
        NotificationManager.IMPORTANCE_DEFAULT); 
      mNotificationManager.createNotificationChannel(channel); 
     } 

     mNotificationManager.notify(0, mBuilder.build()); 
+1

ありがとうございました。 –

+0

@JorgeVieiraあなたが歓迎:) –

関連する問題