android - 为什么我的通知没有出现

标签 android

大家好,我正在使用预先通知管理器,这是代码

Notification note = new Notification();
    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notif);
    contentView.setImageViewResource(R.id.image, R.drawable.notif);
    contentView.setTextViewText(R.id.title, "Focused Crawling");
    contentView.setTextViewText(R.id.text, "Crawling In Progress....");
    note.contentView = contentView;

    Intent notificationIntent = new Intent(this, LoadingActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    note.contentIntent = contentIntent;
    note.vibrate = new long[] { 500L, 200L, 200L, 500L };
    note.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "2");
    note.flags |= Notification.FLAG_NO_CLEAR;

    mgr.notify(1337, note);
    startForeground(1337, note);

为什么它没有出现在状态栏上?

最佳答案

您没有为状态栏指定图标,这是必需的。 在您的代码中添加这样一行:

note.icon = R.drawable.youricon;

参见 Creating a Notification

关于android - 为什么我的通知没有出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8744937/

相关文章:

Android Wear 心率传感器原始光数据

android - 在android中更改选定的 ListView 项目图像问题

android - Fragment 中的 TextureView 从不调用 onSurfaceTextureAvailable

java.lang.NullPointerException : Attempt to invoke virtual method on a null object reference Retrofit

android - 当我点击缩放按钮 map 挂起时,谷歌地图 v2 挂起

android - 从 Android 应用发起 CSD 数据调用

java - 当我尝试通过拖放运行 Android 应用程序时出现意外错误

android - 针对不同 Activity 的 Dagger 注入(inject)

android.provider.Telephony.SMS_RECEIVED 不可用

java - 从 url 加载位图