当前位置: 代码迷 >> Android >> 安装在sd中的程序怎么开机启动
  详细解决方案

安装在sd中的程序怎么开机启动

热度:40   发布时间:2016-04-28 07:58:40.0
安装在sd中的程序如何开机启动
如果程序安装在内存中,设置android.intent.action.BOOT_COMPLETED后即可开机启动,但程序移至sd卡便无法开机启动了,请问是否可以做到sd中的程序如何开机启动

------解决方案--------------------
应该是没有问题的!
只要程序中注册android.intent.action.BOOT_COMPLETED到系统,就能实现开机启动啊

可能是其它方面的问题吧

看看程序有没有访问SDcard的权限等等其它的问题

楼主再看看吧!
------解决方案--------------------
你可以判断SDCard是否已经挂载,如果挂载成功再启动你的程序。
即提供一个监听方法BroadcastReceiver 设置IntentFilter为:
Intent.ACTION_MEDIA_MOUNTED
Intent.ACTION_MEDIA_EJECT
Intent.ACTION_MEDIA_REMOVED 
然后再public void onReceive(Context context, Intent intent) 中实现你的启动逻辑startActivity

网上别人的代码,参考:
private final BroadcastReceiver broadcastRec = new BroadcastReceiver() 

{

[email protected]

  public void onReceive(Context context, Intent intent) {

  if(intent.getAction().equals("android.intent.action.MEDIA_MOUNTED"))//SD 

卡已经成功挂载

  {

  imagepath = 

android.os.Environment.getExternalStorageDirectory();//你的SD卡路径

  }else 

if(intent.getAction().equals("android.intent.action.MEDIA_REMOVED")//各种未挂载状态

  
------解决方案--------------------
intent.getAction().equals("android.intent.action.ACTION_MEDIA_UNMOUNTED")

  
------解决方案--------------------
intent.getAction().equals("android.intent.action.ACTION_MEDIA_BAD_REMOVAL"))

  {

  imagepath = android.os.Environment.getDataDirectory();//你的本地路径

  }

  }

  };

  //在IntentFilter中选择你要监听的行为

  IntentFilter intentFilter = new 

IntentFilter(Intent.ACTION_MEDIA_MOUNTED);

  intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);

  intentFilter.addAction(Intent.ACTION_MEDIA_REMOVED);

  //intentFilter.addAction(Intent.ACTION_MEDIA_SHARED);

  intentFilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);

  //intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);

  //intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);

  intentFilter.addDataScheme("file");

  registerReceiver(broadcastRec, intentFilter);//注册监听函数

  unregisterReceiver(broadcastRec);//使用完注销广播监听函数


------解决方案--------------------
如果程序安装在内部存储中,设置android.intent.action.BOOT_COMPLETED后即可开机启动。你把程序的什么格式放在sd卡中? 就是你所说的把程序移至SD中的操作是具体怎么做的?

目前我可以想到的就是写脚本将sd卡中的程序资源安装上。 
------解决方案--------------------
App Install Location
Broadcast Receivers listening for "boot completed" 
The system delivers the ACTION_BOOT_COMPLETED broadcast before the external storage is mounted to the device. If your application is installed on the external storage, it can never receive this broadcast. 
http://www.ideasandroid.com/android/sdk/docs/guide/appendix/install-location.html
android明确说明了,安装在sd卡上的应用程序是接收不到ACTION_BOOT_COMPLETED消息的,在mount sd卡之前这个消息已经发出了。
  相关解决方案