I want to show my alarm activity, but when my activity started keyguard open fingerprint screen on Xiaomi mi8 miui 11. I can make click back button and I see my screen without unlock. But I want to see my screen right away above lock screen. But I get fingerprint screen first. myunlock code in activity onCreate():
private fun allowOnLockScreen() {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
setTurnScreenOn(true)
setShowWhenLocked(true)
val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
keyguardManager.requestDismissKeyguard(this, object : KeyguardManager.KeyguardDismissCallback() {
override fun onDismissCancelled() {
super.onDismissCancelled()
Log.d("keygurd", "canceled")
}
override fun onDismissError() {
super.onDismissError()
Log.d("keygurd", "error") //when I make requestDismissError, I get error
}
override fun onDismissSucceeded() {
super.onDismissSucceeded()
Log.d("keygurd", "succeded")
}
})
} else {
this.window.addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD or
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
)
}
}
And my AndroidManifest:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alarm">
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:showOnLockScreen="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:excludeFromRecents="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.HOME"/>
</intent-filter>
</activity>
<service android:name=".AlarmService" />
</application>
</manifest>
Also I requested Overlay permission in onCreate():
fun addOverlay() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
val intent = Intent(
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:$packageName")
)
startActivityForResult(intent, 400)
}
}
}
I tried to start my activity from Service both with startActivity and with fullScreenIntent notification. No difference:
class AlarmService : Service() {
override fun onBind(intent: Intent?): IBinder? {
return null
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
onHandleIntent(intent)
return super.onStartCommand(intent, flags, startId)
}
fun onHandleIntent(intent: Intent?) {
Log.d("sdf", "sdf")
val notification: Notification
val notificationBuilder: Notification.Builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val resultIntent = Intent(this, MainActivity::class.java)
// Create the TaskStackBuilder and add the intent, which inflates the back stack
val stackBuilder: TaskStackBuilder = TaskStackBuilder.create(this)
stackBuilder.addNextIntentWithParentStack(resultIntent)
val resultPendingIntent: PendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
val chan =
NotificationChannel("my_service", "afadfs", NotificationManager.IMPORTANCE_HIGH)
chan.lightColor = Color.BLUE
chan.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
val manager =
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager)
manager.createNotificationChannel(chan)
val notificationBuilder =
NotificationCompat.Builder(this, "my_service")
notification = notificationBuilder.setOngoing(true)
.setSmallIcon(com.example.alarm.R.mipmap.ic_launcher)
.setContentTitle("Будильник")
.setPriority(NotificationManager.IMPORTANCE_MIN)
.setCategory(Notification.CATEGORY_SERVICE)
//.setContentIntent(resultPendingIntent) //intent
.build()
val notificationManager = NotificationManagerCompat.from(this)
notificationManager.notify(1, notificationBuilder.build())
} else {
notificationBuilder = Notification.Builder(this)
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher)
notificationBuilder.setContentTitle("Будильник")
notification = notificationBuilder.build()
}
startForeground(1, notification)
Handler().postDelayed({
/*startActivity(Intent(this, MainActivity::class.java).apply { it show me my activity also
flags =
FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or FLAG_ACTIVITY_CLEAR_TASK
})*/
Log.d("run", "run")
val fullScreenIntent = Intent(this, MainActivity::class.java)
val fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT)
var builder = NotificationCompat.Builder(this, "my_service")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEenter image description hereGORY_ALARM)
.setFullScreenIntent(fullScreenPendingIntent, true)
val notificationManager =
NotificationManagerCompat.from(applicationContext)
val notification1 = builder.build()
notificationManager.notify(1, notification1)
startForeground(2, notification1)
}, 5000)
}
}
What am I doing not right? Miui 11 show me fingerprint first. Here screen fingerprint which I get when tried show my alarm activity.