【发布时间】:2018-05-08 09:00:50
【问题描述】:
我的通知有操作按钮。当通知到达锁定屏幕并且用户点击操作按钮时,我需要显示设备 pin 屏幕,输入 pin 后,操作(在我的情况下,操作是对服务器的 API 调用)应该是执行时没有提出通知活动。现在,在锁定屏幕上,直接执行操作,而不提示用户输入设备密码。我想解决这个问题。
当设备解锁时通知到达时,用户应该能够直接点击操作按钮而不会看到通知活动。
我对 stackoverflow 的研究让我遇到了许多相反的问题 - 许多人询问如何在没有设备 pin 的情况下在锁定屏幕上执行操作。但是,就我而言,我从未收到设备引脚提示。当用户在锁定屏幕上执行通知操作时,代码中的哪些设置会显示设备 pin?
我下面的代码会导致在锁定屏幕上执行通知操作而不提示输入密码:
private void displayChallengeNotification(Context context, ChallengeInformation extras) {
/* build the notification */
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
.setSmallIcon(R.drawable.status_bar_icon)
.setContentTitle(context.getString(R.string.push_notification_title))
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(getChallengeContextString(extras)))
.setContentText(context.getString(R.string.push_notification_description))
.setAutoCancel(false)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setColor(context.getResources().getColor(R.color.notification))
.setLocalOnly(true)
.setDefaults(DEFAULTS);
/* set the target of the notification */
PendingIntent challenge =
getChallengePendingIntent(context, extras);
mBuilder.setContentIntent(challenge);
addNotificationActions(mBuilder, context, extras);
challengeTracker.notifyChallenge(extras, context, mBuilder.build());
}
private PendingIntent getChallengePendingIntent(Context context, ChallengeInformation extras) {
Intent challenge = getChallengeIntent(context, extras);
/* set up the back stack so that navigation works as expected */
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(challenge);
int notificationId = extras.getTransactionId().hashCode();
PendingIntent challengePendingIntent = stackBuilder.getPendingIntent(notificationId, 0);
return challengePendingIntent;
}
private static Intent getChallengeIntent(Context context, ChallengeInformation info) {
/* set up the intent to launch the challenge screen */
Intent challenge = new Intent(context, PushChallengeActivity.class);
challenge.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
/* get the information for the challenge */
challenge.putExtras(info.getBundle());
if (info.isChallengeAccepted() != null) {
challenge.putExtra(Constants.IS_CHALLENGE_ACCEPTED, info.isChallengeAccepted());
}
return challenge;
}
【问题讨论】:
-
在屏幕锁定时按下通知中的操作按钮会发生什么?
-
@JeffreyBlattman 直接执行操作,而不提示输入设备引脚。在我的例子中,服务器获得用户响应,通知从设备中消失,仅此而已。
标签: android push-notification google-cloud-messaging