簡體   English   中英

Android自動啟動應用程序

[英]Android autostart application

如何在設備啟動時自動啟動應用程序的服務(可以啟用/禁用此功能)? 我必須在AndroidManifest中包含哪些權限?

謝謝

此權限被使用

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

在您的<application>元素中(確保對BroadcastReceiver使用完全限定的[或相對]類名):

<receiver android:name="com.example.MyBroadcastReceiver">  
    <intent-filter>  
        <action android:name="android.intent.action.BOOT_COMPLETED" />  
    </intent-filter>  
</receiver>

在MyBroadcastReceiver.java中:

package com.example;

public class MyBroadcastreceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent startServiceIntent = new Intent(context, MyService.class);
        context.startService(startServiceIntent);
    }
}



以獲得更多幫助:: http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/ http://blog.gregfiumara.com/archives/82 http://androidgps.blogspot.com/ 2008/09 /啟動功能的Android服務,在引導,為time.html

暫無
暫無

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

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