i'm running an API in service class. When i get the particular response from that api i'm opening the AutoPlay activity. For calling the activity i wrote
Intent intent = new Intent(BackgroundService.this, AutoPlay.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
and inside of onCreate in the AutoPlay activity i wrote the fallowing code to open the activity when device was locked
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
or
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
but above code was not opening the activity when device was locked. So, please any one help me to achive this
Related
I'm trying to open the activity on lock screen when I receive the notification form twilio. But I'm facing issue as it called onDestroy method when screen is locked on call receiving and it doesn't open the required activity.
I tried many solution but none of them worked.
I also tried following code to open activity on Lock screen but it doesn't work.
Window window=getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
I'm working on VOIP application and recently encountered a problem. Some devices are not waking up when screen is locked and app is in background. I've made some tests and found out that:
If app is closed with back button(task destroyed) then screen was locked and startActivity() is called - the screen is unlocked and activity works fine
If app wasn't started in a while(task wasn't created yet) then screen was locked and startActivity() is called - the screen is unlocked and activity works fine
If app was in foreground then screen was locked and startActivity() is called - the screen is unlocked and activity works fine
If user pressed the HOME button, thus putting the task in background and then screen was locked and startActivity() is called - IT DOESN'T WORK, the screen is off and activity's onCreate is not called
So, I guess it's somehow relevant with home button or the fact that application was in background when screen gets locked. The app calls startActivity() when firebase message received or JNI triggered some callbacks
Here is how I unlock the screen:
if (powerManager != null) {
wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "App:wakeuptag");
wakeLock.acquire(1000 * 60);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setShowWhenLocked(true);
setTurnScreenOn(true);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
} else {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
}
And here is how I start the activity:
Intent intent = new Intent(context, VCEngine.appInfo().getActivity(ActivityType.CALL));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NO_ANIMATION);
if (!(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mIsCallFromBackground.set(!AppUtils.isAppOnForeground());
}
intent.putExtra(
context.getString(R.string.extra_conference_join_or_create),
msg);
intent.putExtra(context.getString(R.string.extra_is_audio_call), isAudioCall);
intent.putExtra("isConference", isConference());
context.startActivity(intent);
I want to make something like alarm activity, but it only triggered over certain push notification.
I've been pulling my hair to achieve that, combining answer here and there(and many more that i couldn't refer here). Now I already can show the activity over the lock screen, but i'm stuck on getting the onClick event listener to dismiss the alarm.
So far here's my codes:
it's onCreate of my Activity:
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
setContentView(R.layout.alarm);
ButterKnife.bind(this);
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "Alarm");
wakeLock.acquire();
dismissButton.setOnClickListener(v -> Log.w("button", "Clicked"));
the Activity on manifest:
<activity android:name=".{package}.Alarm"
android:showOnLockScreen="true"
android:theme="#style/AppTheme.WhiteAccent"
android:screenOrientation="sensorPortrait"/>
and it's where i call my Activity from my notificationService
Intent intent = new Intent(this, MewsAlarm.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("judul", data.get("title"));
startActivity(intent);
am I did it wrong?
I only test it on my phone though (4.4.2), so i don't even know the activity will shown on other device. But really, can someone help me to get over this please?
thank you for the suggestion guys, my bad i haven't search the related topic thoroughly, so i found the answer over here:
https://stackoverflow.com/a/4482868/7852331
so i just add
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
to my flags above, and voila i get the click event.
Trying to show my Overlay activity over device lock screen - Its Working fine. The problem when my phone ringing | Alarm ringing that time I can see the overlay only. Cancel my overlay then only i can see.. how to avoid that
My code for display activity
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
I'm creating an application that uses alarms.
That's how I start alarm activity (in broadcast receiver)
Intent myIntent = new Intent(context, AlarmActivity.class);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(myIntent);
When alarm activity is closed, and the application is started again from home button, this activity is launched each time instead of my splash screen, and I have to remove last launched apps from recent apps menu, only then the splash screen is started when the application is launched.
By the way, the above flags are needed to unlock the screen if locked when the alarm is fired, and I have this in my alarm activity:
#Override
public void onAttachedToWindow() {
this.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
}
Any one has an idea?