20

有没有办法在启动后自动启动和启动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)

谢谢

4

4 回答 4

1

根据谷歌的说法,你不应该把任何你想在启动时运行的应用程序放在外部驱动器上。

“系统在将外部存储挂载到设备之前发送 ACTION_BOOT_COMPLETED 广播。如果您的应用程序安装在外部存储上,它永远无法接收到此广播。”

http://developer.android.com/guide/topics/data/install-location.html#ShouldNot

于 2015-09-14T22:59:50.360 回答
1

请在清单文件中提及。

</uses-permission>    
<receiver android:name=".BootReceiver"
    android:enabled="true"
    android:exported="true"
    android:label="BootReceiver">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED"></action>
    </intent-filter>
</receiver>

提供权限“android.permission.RECEIVE_BOOT_COMPLETED”作为清单的孩子。

还有一件事你的应用程序不能安装在 sdcard 中。

于 2015-07-15T10:40:21.797 回答
1

尝试使用<receiver android:name=".BootCompleteReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> </intent-filter> </receiver>

和这个<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

也许 QUICKBOOT_POWERON 可以帮助你

于 2015-07-17T14:39:51.900 回答
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>

在扩展应用程序的类中:

registerReceiver(new broadcastReciever(), new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE));

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

应该这样做;随时要求更多帮助/澄清。

于 2013-08-14T14:42:16.150 回答