Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带屏幕锁的应用程序调用_Android - Fatal编程技术网

Android 带屏幕锁的应用程序调用

Android 带屏幕锁的应用程序调用,android,Android,我想在屏幕解锁和启动时立即启动一个应用程序。怎么可能呢?我需要做哪些更改 要在屏幕锁定时启动应用程序,您需要为Intent注册一个。ACTION\u screen\u OFF Intent有关更多信息,请查看示例 要在启动时启动应用程序,您需要一个广播接收器来侦听启动完成的操作,请参阅 首先,您需要清单中的权限: <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 现在,当手机启动

我想在屏幕解锁和启动时立即启动一个应用程序。怎么可能呢?我需要做哪些更改

  • 要在屏幕锁定时启动应用程序,您需要为Intent注册一个。ACTION\u screen\u OFF Intent有关更多信息,请查看示例

  • 要在启动时启动应用程序,您需要一个广播接收器来侦听启动完成的操作,请参阅

  • 首先,您需要清单中的权限:

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    
    现在,当手机启动时,您的服务应该正在运行

    <service android:name=".MyService" android:label="My Service">
        <intent-filter>
            <action android:name="com.myapp.MyService" />
        </intent-filter>
    </service>
    
    <receiver
        android:name=".receiver.StartMyServiceAtBootReceiver"
        android:enabled="true"
        android:exported="true"
        android:label="StartMyServiceAtBootReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    
    public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
                Intent serviceIntent = new Intent("com.myapp.MySystemService");
                context.startService(serviceIntent);
            }
        }
    }