如果在/sdcard
上有自动启动的话,有没有办法启动和安装android应用程序?
好的,可能是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)
感谢
扬
答案 0 :(得分:1)
根据谷歌的说法,你不应该在外部驱动器上放置你想要在启动时运行的任何应用程序。
“系统在外部存储装置安装到设备之前传送ACTION_BOOT_COMPLETED广播。如果您的应用程序安装在外部存储设备上,它将永远无法接收此广播。”
http://developer.android.com/guide/topics/data/install-location.html#ShouldNot
答案 1 :(得分: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>
并且在扩展Application的类中:
registerReceiver(new broadcastReciever(), new IntentFilter(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE));
并且不要忘记添加RECEIVE_BOOT_COMPLETED
权限并注册在Android Manifest中扩展Application的类。
这应该做;随时可以要求更多帮助/澄清。
答案 2 :(得分:0)
尝试使用<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帮助你