在锁定屏幕android中点击通知解锁屏幕

时间:2017-06-07 08:16:54

标签: android

我在锁定屏幕上显示了自定义通知。单击通知后,我正在使用广播待定意图向我的应用发送消息。之后会在广播接收器中开始活动。

问题是,一旦我点击通知,它就不会要求用户解锁屏幕,而是在锁定屏幕后面启动活动。当我手动解锁屏幕时,我可以看到。

我的要求是在通知的点击事件发送广播后立即要求用户解锁屏幕。我该怎么做?

这是我试过的代码。

private void showNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    Notification notification = builder.build();
    notification.bigContentView = createCustomView(context);
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(getNotificationId(), notification);
}

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

private RemoteViews createCustomView(Context context) {
   RemoteViews customView = new RemoteViews(context.getPackageName(), R.layout.custom_layout);
   if (customView != null) {
        customView.setOnClickPendingIntent(R.id.my_view, getNotificationClickIntent());
   }
   return customView;
}

找到解决方案here

在待处理的意图中使用活动意图而不是服务或广播

PendingIntent.getActivity(context, 0, intent,
                                 PendingIntent.FLAG_UPDATE_CURRENT);

0 个答案:

没有答案
相关问题