簡體   English   中英

Android - 如何在啟動后在/ sdcard上啟動應用程序

[英]Android - How to start an application on the /sdcard after boot

有沒有辦法如何啟動和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)

謝謝
一月

請在清單文件中提及。

</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”作為清單的孩子。

還有一件事你的應用程序不能安裝在SD卡中。

根據谷歌的說法,你不應該在外部驅動器上放置你想要在啟動時運行的任何應用程序。

“在外部存儲裝置安裝到設備之前,系統會發送ACTION_BOOT_COMPLETED廣播。如果您的應用程序安裝在外部存儲設備上,它將永遠無法接收此廣播。”

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

我通常都會為廣播接收器注冊每個意圖過濾器(Android Manifest以及在擴展Application的類中動態)

在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的類。

這應該做; 隨時可以要求更多的幫助/澄清。

嘗試使用<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幫助你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM