如何让android studio中的应用程序在手机被锁定的情况下工作。假设在任何紧急情况下,如果用户在手机上滑动或按下锁定按钮2次,当手机被锁定时,它会将其位置发送到保存的紧急号码。有什么想法吗?
发布于 2021-06-06 12:30:03
由于您的应用程序未在使用中,并且您希望侦听某些特定的事件并执行特定的任务,因此您应该使用Service。您可以按照此答案中的说明创建LockService。
https://stackoverflow.com/a/30030372/4491971
您可以编写用于将位置发送到已保存紧急号码的操作,而不是像答案中解释的那样启动活动。
package com.example.userpresent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
public class ScreenReceiver extends BroadcastReceiver {
public static boolean wasScreenOn = true;
@Override
public void onReceive(final Context context, final Intent intent) {
if(intent.getAction().equals(Intent.ACTION_USER_PRESENT)) {
// YOUR OPERATION CAN BE DONE HERE
}
}
}https://stackoverflow.com/questions/67855066
复制相似问题