【发布时间】:2020-01-08 08:50:27
【问题描述】:
我正在尝试清除通知。但它仍然存在。无法从通知中打开片段活动。下面是我的代码,
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int sticky;
try {
AndroidLogger.log(5, TAG, "Missed call notification on start");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH; //Important for heads-up notification
NotificationChannel channel = new NotificationChannel("1", "Call Notification", importance);
channel.setDescription("Get alert for missed call");
channel.setShowBadge(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
Intent notifyIntent = new Intent(this, ViewFragment.class);
notifyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, notifyIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "1")
.setSmallIcon(R.drawable.nexge_logo)
.setContentTitle("Missed Call")
.setContentText(intent.getStringExtra("Number"))
.setContentIntent(pIntent)
.setAutoCancel(true)
.setPriority(Notification.PRIORITY_MAX);
Notification buildNotification = mBuilder.build();
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//mNotifyMgr.notify(1, buildNotification);
startForeground(1,buildNotification);
} catch (Exception exception) {
AndroidLogger.error(1, TAG, "Exception while starting service", exception);
}
return START_NOT_STICKY;
}
}
谁能帮我解决这个问题。提前致谢。 以下是我没有得到正确答案的另一个问题。也帮助我 About Notification for Missed Call in android
【问题讨论】:
-
请加入这个群Android & Kotlin Experts并联系我,我会在那里解释。
-
@Ali 我没有足够的声望来聊天
-
您有兄弟,您只需等待管理员接受您的请求。您发送加入请求?
-
好吧,忘记组了。你的问题是如果你点击通知然后片段加载不正确?
-
@Ali ya 没错,还有一件事是右滑后无法清除顶部栏上的通知
标签: java android android-studio notifications fragment