我想创建一个像这样的应用程序:
拿起设备时,我将其解锁,此应用将被打开。然后,此应用将显示使用平板电脑的折衷条款。有两种选择,允许或拒绝。如果我选择允许,该应用程序将完成;当我选择拒绝时,直到选择允许,什么都不会发生。
然后,在我使用设备后,它将锁定,然后...我将解锁,并且该应用程序将再次出现在这里!
解锁设备后如何使该应用自动运行?
在清单文件中添加接收器
<receiver android:name=".ScreenReceiver">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
创建一个广播接收器,当手机解锁时,该接收器可以打开应用程序。
public class ScreenReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
System.out.println(intent.getAction());
if (intent.getAction().equals(Intent.ACTION_USER_PRESENT))
{
Intent intent1 = new Intent(context,MainActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8555 次 |
| 最近记录: |