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?