android應(yīng)用實(shí)現(xiàn)開機(jī)自動(dòng)啟動(dòng)方法
原理:Android系統(tǒng)在開機(jī)的時(shí)候會(huì)發(fā)出一個(gè)廣播。這樣我們就可以接收這個(gè)廣播,然后啟動(dòng)我們的應(yīng)用。廣播接收器必須在xml里面配置,因?yàn)閤ml里面配置的廣播接收器 是不隨著應(yīng)用的退出而退出的。
廣播接收器:
package com.yangshidesign.boot; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class BootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, UnityPlayerNativeActivity.class); //這個(gè)必須添加flags i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
在manifest的application標(biāo)簽里面配置:
<!-- 開機(jī)啟動(dòng) --> <receiver android:name="com.yangshidesign.boot.BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <category android:name="android.intent.category.HOME"/> </intent-filter> </receiver>
加上權(quán)限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
這樣就可以了。
我用的是 紅米note 測試的,要煩煩的設(shè)置一番:
點(diǎn)擊 設(shè)置 》應(yīng)用》找到你的應(yīng)用》點(diǎn)擊,拉到底下的 權(quán)限管理》自動(dòng)啟動(dòng)》完成。
相關(guān)文章
Android App后臺(tái)震動(dòng)的實(shí)現(xiàn)步驟詳解
這篇文章主要為大家介紹了Android App后臺(tái)震動(dòng)的實(shí)現(xiàn)步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11Android TextView實(shí)現(xiàn)多文本折疊、展開效果
這篇文章主要為大家詳細(xì)介紹了Android TextView實(shí)現(xiàn)多文本折疊、展開效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05Android使用setContentView實(shí)現(xiàn)頁面的轉(zhuǎn)換效果
這篇文章主要介紹了Android如何使用setContentView實(shí)現(xiàn)頁面的轉(zhuǎn)換效果,幫助大家更好的利用Android進(jìn)行開發(fā),感興趣的朋友可以了解下2021-01-01Android實(shí)現(xiàn)簡單的popupwindow提示框
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡單的popupwindow提示框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10