如下是接收廣播的程序代碼: android
package com.android.Samkoonhmi.system;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootBroadcastReceiver extends BroadcastReceiver {
static final String ACTION = "android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION)){
Intent bootitt=new Intent(context,com.android.Samkoonhmi.activity.LoginActivity.class);
bootitt.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(bootitt);
}
}
} ide
如下是Manifest.xml中註冊廣播接收器的代碼: xml
<receiver android:name="com.android.Samkoonhmi.system.BootBroadcastReceiver" >
<intent-filter>
<!-- <action android:name="android.intent.action.BOOT_COMPLETED" /> -->
</intent-filter>
</receiver> get
但發現若是是用adb install來安裝apk,那麼,第一次啓動時,不會自動啓動。
it