Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android notification only sound plays通知未显示在通知抽屉中_Android_Android Notifications - Fatal编程技术网

android notification only sound plays通知未显示在通知抽屉中

android notification only sound plays通知未显示在通知抽屉中,android,android-notifications,Android,Android Notifications,我正在尝试使用AlarmManager和notification manager在特定时间启动通知。我面临一个奇怪的问题。触发通知时,仅播放声音,但通知抽屉中不显示通知。 我在日志中发现了一个错误 04-26 11:32:09.217 1222-1222/? E/NotificationService﹕ WARNING: In a future release this will crash the app: com.example.shiv.selftweak 我的密码是 调用Alar

我正在尝试使用AlarmManager和notification manager在特定时间启动通知。我面临一个奇怪的问题。触发通知时,仅播放声音,但通知抽屉中不显示通知。 我在日志中发现了一个错误

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的类

        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);
FireNotification类

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;
}
}

安卓梅尼费斯特酒店

 <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
。如果您错过了其中任何一个,通知将不会显示!这是明确规定的(你也可以在那里阅读更多关于通知的信息)。

是的,我也发现了同样的问题。谢谢但android应该为同样的问题抛出一个异常