I have a share button in the GCM notification
. On click of the share button, I need to launch share intent. Everything works perfectly. Only problem that I'm facing is Lollipop
lock screen feature. When I click share button from lock screen, my intent dialog appears below the lock screen and user has to unlock the screen to see the dialog. I want to unlock the screen programatically, when share button is clicked.
I tried with Power Manager, But all it's wakeClock
flags are deprecated and WindowManager.LayoutParams.Flag_KEEP_SCREEN_ON
is recommened to use. But I'm not using activity here. I'm using broadcastReciever context
. and hence I cannot use getWindow()
method.
I also tried with KeyguardManager
. But even disableKeyguard()
is deprectated.
I cannot use the Intent.ACTION_SCREEN_ON
, as this should be used, if we want to perform any action after screen is unlocked.
i had used below intent to programmatically close the notification tray:
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
mContext.sendBroadcast(it);
Is there a similar intent, that can be broadcasted to unlock the screen
Updated Code using DevicePolicyManager:
public static void handleShareBtnClick(Context context, String message) {
GcmHelper helper = new GcmHelper();
helper.shareMessage(context, message);
if(Utility.isLollypopAndAbove()){
helper.unlockLockScreen();
}
helper.launchShareforForAlert();
}
public void unlockLockScreen(){
DevicePolicyManager devicePolicyMngr= (DevicePolicyManager) mContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName compName=new ComponentName(mContext, DeviceAdminReceiver.class);
if(!devicePolicyMngr.isAdminActive(compName))
devicePolicyMngr.removeActiveAdmin(compName);
}
Even after using DevicePolicyManager, It's not unlocking my screen
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…