【发布时间】:2016-11-24 13:05:54
【问题描述】:
我在锁定屏幕中显示了一个自定义通知。单击通知后,我正在使用广播挂起意图向我的应用程序发送消息。稍后在广播接收器中启动一个活动。
问题是,一旦我单击通知,它就会从锁定屏幕中消失,并且活动会在锁定屏幕后面启动。它不会要求用户解锁屏幕。
我的要求是在通知的点击事件发送广播后立即要求用户解锁屏幕。我该怎么做?
我可以找到看起来像我的问题的this 问题。但遗憾的是没有答案。
这是一些解释我所做的通知创建的代码。
/**
* Method to render Notification
*/
private void showNotification() {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
/* set mandatory stuff on builder */
Notification notification = builder.build();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
notification.bigContentView = createCustomView(context);
}
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(getNotificationId(), notification);
}
/**
* Method to return notification click's PendingIntent
*/
private PendingIntent getNotificationClickIntent() {
Intent bcIntent = new Intent(OPEN_APP);
bcIntent.putExtra(EXTRA_DEEP_LINK_URL, getDeepLinkUrl());
return PendingIntent.getBroadcast(
context, getReqCode(), bcIntent, PendingIntent.FLAG_ONE_SHOT);
}
/**
* Method to create custom view for notification
*/
private RemoteViews createCustomView(Context context) {
RemoteViews customView = new RemoteViews(context.getPackageName(), R.layout.custom_layout);
if (customView != null) {
// set dat on views
customView.setOnClickPendingIntent(R.id.my_view, getNotificationClickIntent());
}
return customView;
}
【问题讨论】:
-
您最终是否为这种情况找到了更优雅的解决方案?
-
@AmirUval 我最终使用了一个没有 UI 的中间活动
-
谢谢。我最终也是这样做的。
标签: android notifications lockscreen