[Android] 開機啟動與解鎖啟動
2012-04-11 00:00
1 minute read

BroadcastReceiver 開機啟動與解鎖啟動

主要是這兩個intent:

Intent.ACTION_BOOT_COMPLETED //開機

Intent.ACTION_USER_PRESENT //解鎖

只要建立下面的 Receiver

public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(final Context context, final Intent intent) {
        final String action = intent.getAction();
        if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
      // TODO 開機啟動
        } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
            // TODO 解鎖啟動
        }
    }   
}

並且在 AndroidManifest.xml 裡宣告就可以了


Back to posts


comments powered by Disqus