<!-- 开机自动启动应用 -->
<receiver android:name="io.dcloud.myself.BootBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</receiver>
<!-- u盘插入/拔出得启应用 -->
<receiver android:name="io.dcloud.myself.UsbBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_MOUNTED"/>
<action android:name="android.intent.action.MEDIA_UNMOUNTED"/>
<action android:name="android.intent.action.MEDIA_REMOVED"/>
<category android:name="android.intent.category.LAUNCHER"></category>
<data android:scheme="file"/>
</intent-filter>
</receiver>
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import io.dcloud.PandoraEntry;
public class BootBroadcastReceiver extends BroadcastReceiver {
static final String action_boot="android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
Log.d("============", intent.getAction());
String action = intent.getAction();
if (action.equals(action_boot)){
// 注意H5+SDK的Main Activity为PandoraEntry(见AndroidMainfest.xml)
Intent bootMainIntent = new Intent(context, PandoraEntry.class);
// 这里必须为FLAG_ACTIVITY_NEW_TASK
bootMainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(bootMainIntent);
}
}
}
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import io.dcloud.PandoraEntry;
public class UsbBroadcastReceiver extends BroadcastReceiver {
static final String action_media_unmounted="android.intent.action.MEDIA_UNMOUNTED";
static final String action_media_removed="android.intent.action.MEDIA_REMOVED";
@Override
public void onReceive(Context context, Intent intent) {
Log.d("============", intent.getAction());
String action = intent.getAction();
if(action.equals(action_media_unmounted) || action.equals(action_media_removed)){
// 注意H5+SDK的Main Activity为PandoraEntry(见AndroidMainfest.xml)
Intent bootMainIntent = new Intent(context, PandoraEntry.class);
// 这里必须为FLAG_ACTIVITY_NEW_TASK
bootMainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(bootMainIntent);
android.os.Process.killProcess(android.os.Process.myPid());
}
}
}