android 通知只播放声音通知不显示在通知抽屉中
android notification only sound plays notification is not shown in notification drawer
我正在尝试使用 AlarmManager 和通知管理器在特定时间触发通知。我面临一个奇怪的问题。当通知被触发时,只播放声音但通知不会显示在通知抽屉中。
我在日志中收到一个错误
04-26 11:32:09.217 1222-1222/? E/NotificationService﹕ WARNING: In a future release this will crash the app: com.example.shiv.selftweak
我的代码是 .
调用AlarmManager的class
Intent intent1 = new Intent(this, FireNotification.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 1000, intent1, 0);
AlarmManager am = (AlarmManager)this.getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(), pendingIntent);
火灾通知class
public class FireNotification extends Service {
@Override
public void onCreate() {
Intent intent = new Intent(this, MainActivity.class);
long[] pattern = {0, 300, 0};
PendingIntent pi = PendingIntent.getActivity(this, 1234, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setContentTitle("Self tweak")
.setContentText("Habbits are waiting for last dones")
.setVibrate(pattern)
.setAutoCancel(false);
mBuilder.setContentIntent(pi);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(false);
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.notify(1234, mBuilder.build());
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Android 月经
<service android:name=".FireNotification"></service>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
当通知触发时只播放声音。但它没有显示在不显示通知的通知抽屉中。
问题是您没有指定 mBuilder.setSmallIcon(R.drawable.ic_launcher)
。
基本上你必须设置smallIcon
、contentTitle
和contentText
。如果您错过了其中任何一个,则根本不会显示通知!这已明确指定 HERE(您也可以在那里阅读有关通知的更多信息)。
我正在尝试使用 AlarmManager 和通知管理器在特定时间触发通知。我面临一个奇怪的问题。当通知被触发时,只播放声音但通知不会显示在通知抽屉中。 我在日志中收到一个错误
04-26 11:32:09.217 1222-1222/? E/NotificationService﹕ WARNING: In a future release this will crash the app: com.example.shiv.selftweak
我的代码是 .
调用AlarmManager的class
Intent intent1 = new Intent(this, FireNotification.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 1000, intent1, 0);
AlarmManager am = (AlarmManager)this.getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(), pendingIntent);
火灾通知class
public class FireNotification extends Service {
@Override
public void onCreate() {
Intent intent = new Intent(this, MainActivity.class);
long[] pattern = {0, 300, 0};
PendingIntent pi = PendingIntent.getActivity(this, 1234, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setContentTitle("Self tweak")
.setContentText("Habbits are waiting for last dones")
.setVibrate(pattern)
.setAutoCancel(false);
mBuilder.setContentIntent(pi);
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
mBuilder.setAutoCancel(false);
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
mNotificationManager.notify(1234, mBuilder.build());
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Android 月经
<service android:name=".FireNotification"></service>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
当通知触发时只播放声音。但它没有显示在不显示通知的通知抽屉中。
问题是您没有指定 mBuilder.setSmallIcon(R.drawable.ic_launcher)
。
基本上你必须设置smallIcon
、contentTitle
和contentText
。如果您错过了其中任何一个,则根本不会显示通知!这已明确指定 HERE(您也可以在那里阅读有关通知的更多信息)。