如何在啟動(dòng)時(shí)啟動(dòng)我的應(yīng)用程序?我嘗試使用示例代碼這,這個(gè)鏈接,但它似乎過(guò)時(shí)了,它沒(méi)有工作。那么,當(dāng)Android完成引導(dǎo)時(shí),我需要做哪些更改,以及要讓?xiě)?yīng)用程序自動(dòng)啟動(dòng)哪些文件呢?
3 回答

回首憶惘然
TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊
AndroidManifest.xml
:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
AndroidManifest.xml
<service android:name=".MyService" android:label="My Service"> <intent-filter> <action android:name="com.myapp.MyService" /> </intent-filter></service><receiver android:name=".receiver.StartMyServiceAtBootReceiver" android:label="StartMyServiceAtBootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter></receiver>
public class StartMyServiceAtBootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { Intent serviceIntent = new Intent(context, MyService.class); context.startService(serviceIntent); } }}
- 3 回答
- 0 關(guān)注
- 420 瀏覽
添加回答
舉報(bào)
0/150
提交
取消