博客列表 >html5 + app 重启

html5 + app 重启

弘德誉曦的博客
弘德誉曦的博客原创
2019年11月10日 16:09:531472浏览
  1. <!-- 开机自动启动应用 -->
  2. <receiver android:name="io.dcloud.myself.BootBroadcastReceiver">
  3. <intent-filter>
  4. <action android:name="android.intent.action.BOOT_COMPLETED" />
  5. <category android:name="android.intent.category.LAUNCHER"></category>
  6. </intent-filter>
  7. </receiver>
  8. <!-- u盘插入/拔出得启应用 -->
  9. <receiver android:name="io.dcloud.myself.UsbBroadcastReceiver">
  10. <intent-filter>
  11. <action android:name="android.intent.action.MEDIA_MOUNTED"/>
  12. <action android:name="android.intent.action.MEDIA_UNMOUNTED"/>
  13. <action android:name="android.intent.action.MEDIA_REMOVED"/>
  14. <category android:name="android.intent.category.LAUNCHER"></category>
  15. <data android:scheme="file"/>
  16. </intent-filter>
  17. </receiver>
  1. import android.content.BroadcastReceiver;
  2. import android.content.Context;
  3. import android.content.Intent;
  4. import android.util.Log;
  5. import io.dcloud.PandoraEntry;
  6. public class BootBroadcastReceiver extends BroadcastReceiver {
  7. static final String action_boot="android.intent.action.BOOT_COMPLETED";
  8. @Override
  9. public void onReceive(Context context, Intent intent) {
  10. Log.d("============", intent.getAction());
  11. String action = intent.getAction();
  12. if (action.equals(action_boot)){
  13. // 注意H5+SDK的Main Activity为PandoraEntry(见AndroidMainfest.xml)
  14. Intent bootMainIntent = new Intent(context, PandoraEntry.class);
  15. // 这里必须为FLAG_ACTIVITY_NEW_TASK
  16. bootMainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  17. context.startActivity(bootMainIntent);
  18. }
  19. }
  20. }
  21. import android.content.BroadcastReceiver;
  22. import android.content.Context;
  23. import android.content.Intent;
  24. import android.util.Log;
  25. import io.dcloud.PandoraEntry;
  26. public class UsbBroadcastReceiver extends BroadcastReceiver {
  27. static final String action_media_unmounted="android.intent.action.MEDIA_UNMOUNTED";
  28. static final String action_media_removed="android.intent.action.MEDIA_REMOVED";
  29. @Override
  30. public void onReceive(Context context, Intent intent) {
  31. Log.d("============", intent.getAction());
  32. String action = intent.getAction();
  33. if(action.equals(action_media_unmounted) || action.equals(action_media_removed)){
  34. // 注意H5+SDK的Main Activity为PandoraEntry(见AndroidMainfest.xml)
  35. Intent bootMainIntent = new Intent(context, PandoraEntry.class);
  36. // 这里必须为FLAG_ACTIVITY_NEW_TASK
  37. bootMainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  38. context.startActivity(bootMainIntent);
  39. android.os.Process.killProcess(android.os.Process.myPid());
  40. }
  41. }
  42. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议