2017-08-31 11 views
3

Android O通知の変更に対応するようにコードを書き直しました。通知が機能しなくなりました。 SDKバージョン26以降をターゲットにしています。Android Oが通知を送信する

通知の処理に手伝ってください。どんな助けもありがとうございます。

public void createNotificationChannel() { 
NotificationChannel messagesChannel = new NotificationChannel(MESSAGES_CHANNEL, context.getString(R.string.channel_messages), 
      NotificationManagerCompat.IMPORTANCE_HIGH); 
    messagesChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), 
      new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build()); 
    messagesChannel.setVibrationPattern(new long[]{0, 1000, 1000, 1000, 1000}); 
    messagesChannel.setLightColor(Color.WHITE); 
    messagesChannel.setShowBadge(true); 
    notificationManager.createNotificationChannel(messagesChannel); 
} 
    public void showMessageNotification(final String conversationId, final String message) { 
     Intent contentIntent = ConversationDetailsActivity.getLaunchIntent(this, conversationId); 
     contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

     TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
     stackBuilder.addParentStack(ConversationDetailsActivity.class); 
     stackBuilder.addNextIntent(contentIntent); 

     PendingIntent contentPendingIntent = stackBuilder.getPendingIntent(conversationId.hashCode(), FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); 

     Notification notification = buildNotification(R.drawable.ic_message_24dp, message, contentPendingIntent); 
     notificationManager.notify(conversationId.hashCode(), notification); 
    } 
    private Notification buildNotification(final int iconResId, final String message, final PendingIntent contentPendingIntent) { 
     NotificationCompat.Builder builder = new NotificationCompat.Builder(this, MESSAGES_CHANNEL); 
     Notification notification = builder 
       .setSmallIcon(iconResId) 
       .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) 
       .setContentTitle(getString(R.string.notification_title)) 
       .setContentText(message) 
       .setContentIntent(contentPendingIntent) 
       .setPriority(NotificationCompat.PRIORITY_HIGH) 
       .build(); 
     notification.flags |= Notification.FLAG_AUTO_CANCEL; 
     return notification; 
    } 

私のbuild.gradleから

compileSdkVersion 26 
buildToolsVersion '26.0.1' 
defaultConfig { 
    applicationId "com.xxxxxxxx" 
    minSdkVersion 17 
    targetSdkVersion 26 
    versionCode 21 
    versionName '1.13' 
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
    multiDexEnabled true 
} 
+0

sdk 26をコンパイルしますか?あなたのgradle.build(アプリケーション)を見ることはできます – MrAppMachine

+0

@MrAppMachineはbuild.gradleを追加 –

答えて

1

私の通知のために音/振動を設定するのを忘れました。音声/振動が設定されている優先度> =高の通知のみを処理します。

0

を使用すると、通知マネージャを作成していることを確認します。通知の設定方法については、here

こちらをご覧ください。

+0

あなたが作成するものではありません。私はそのようにインスタンスを取得します:notificationManager =(NotificationManager)context.getSystemService(NOTIFICATION_SERVICE);それを使用してください。 –

+0

投稿されたリンクのコードを試しました – MrAppMachine

+1

これは私のコードを入手した場所です。それは動作しません –

関連する問題