Android - 如何在启动后在/ sdcard上启动应用程序

Jan*_*mec 20 boot android sd-card broadcastreceiver

有没有办法如何启动和Android应用程序自动启动后,如果它在/sdcard

好吧,可能是BroadcastReceiver.但哪个行动是正确的呢?

ACTION_BOOT_COMPLETED - does not work if it is on the /sdcard (documented)
ACTION_MEDIA_MOUNTED - does not work if it is on the /sdcard (which is undocumented)
ACTION_EXTERNAL_APPLICATIONS_AVAILABLE - does not work, I do not know why
ACTION_USER_PRESENT - does not work if the BroadcastReceiver is registered in AndroidManifest (which is undocumented, but documentation bug has been reported)
Run Code Online (Sandbox Code Playgroud)

谢谢
Jan

Kam*_*med 0

我通常以两种方式注册广播接收器的每个意图过滤器(Android Manifest 以及在扩展应用程序的类中动态注册)

在AndroidManifest.xml中为:

    <receiver
            android:name=".broadcastReciever"
            android:enabled="true"
            android:exported="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE" />
            </intent-filter>
        </receiver>
Run Code Online (Sandbox Code Playgroud)

在扩展 Application 的类中:

registerReceiver(new broadcastReciever(), new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE));
Run Code Online (Sandbox Code Playgroud)

并且不要忘记在 Android Manifest 中添加RECEIVE_BOOT_COMPLETED权限并注册扩展 Application 的类。

这应该做;请随时寻求更多帮助/说明。