Blogger Information
Blog 143
fans 1
comment 0
visits 442568
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
html5 + app 重启
弘德誉曦的博客
Original
1473 people have browsed it
  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. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post