我正在尝试创建一个自动运行服务:以便应用程序在每次解锁屏幕后、输入图形密钥或密码(如果存在)后启动(在 Android 7、8、9、10 上)。我通过 borocast 接收器 (ACTION_SCREEN_OFF) 动态编写了代码,但它在应用程序在堆栈上(运行)时工作,我希望它始终启动。通过在 android 9 中的清单中注册的方法已经不适用于侦听器。如何实施?
public class WordsBase extends AppCompatActivity {
ScreenReceiver resiverStart;
@Override
protected void onPause() {
super.onPause();
resiverStart= new ScreenReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(resiverStart,filter);
}
}
public class ScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
Intent intent1 = new Intent(context, WordsBase.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
throw new UnsupportedOperationException("Not yet implemented");
}
}