0
我们需要显示信息而无需显示解锁屏幕。 我们能够通过这样的代码通常这样做:通过点击通知图标在锁屏上方显示Android活动
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
但在这种情况下,它应该是在通知栏中点击提示图标。如何才能做到这一点?
我有一个服务在屏幕解锁后运行正常,工作正常。它打开图标点击活动。但是当屏幕被锁定时,我无法做到这一点。
public class notifysrvc extends Service {
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
showRecordingNotification();
return Service.START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroy", Toast.LENGTH_LONG).show();
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
private void showRecordingNotification() {
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.lifegaurdicon12)
.setContentTitle("Emergency")
.setOngoing(true)
.setPriority(Notification.PRIORITY_MAX)
.setContentText("Click here!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, Menu.class);
//Tried this add flags to make it work
resultIntent.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(Menu.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, mBuilder.build());
}
}