2017-12-09 1 views
0

So zeigen Sie eine Benachrichtigung wie die Qualitätszeit an. Ich verwende den folgenden Code Benachrichtigung angezeigt werden, aber es gibt mir Illegal: Ungültige WichtigkeitsstufeWie kann eine Benachrichtigung wie diese oder mit IMPORTANCE_UNSPECIFIED angezeigt werden?

enter image description here

mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
CharSequence name = getString(R.string.app_name); 
// Create the channel for the notification 
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, 
     NotificationManager.IMPORTANCE_UNSPECIFIED); 

// Set the Notification Channel for the Notification Manager. 
mNotificationManager.createNotificationChannel(mChannel); 

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) 
     .setContentTitle(getString(R.string.app_name)) 
     .setAutoCancel(true); 

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(
     this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); 

builder.setContentIntent(contentIntent); 

Notification notification = builder.build(); 
startForeground(1, notification); 

diesen Fehler:

java.lang.IllegalArgumentException: Invalid importance level 
at android.os.Parcel.readException(Parcel.java:1950) 
at android.app.INotificationManager$Stub$Proxy.createNotificati‌onChannels(INotifica‌tionManager.java:155‌6) 
at android.app.NotificationManager.createNotificationChannels(N‌otificationManager.j‌ava:453) 
at android.app.NotificationManager.createNotificationChannel(No‌tificationManager.ja‌va:441) 
at com.app.MyService.onCreate(ScreenService.java:167) – 
Add Comment Collapse 

Antwort

Verwandte Themen