android 广播安装指定下载的apk

// 广播出去,由广播接收器来处理下载完成的文件
  Intent sendIntent = new Intent("com.test.downloadComplete");
  // 把下载好的文件的保存地址加进Intent
  sendIntent.putExtra("downloadFile", file.getPath());
  sendBroadcast(sendIntent);

 

 <receiver android:name="com.yuxin.mhealth.ui.dbmanager.DownLoadBR" >
            <intent-filter>
                <action android:name="com.test.downloadComplete" >
                </action>
            </intent-filter>
        </receiver>

 

public class DownLoadBR  extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent install = new Intent(Intent.ACTION_VIEW);
        String pathString = intent.getStringExtra("downloadFile");
        install.setDataAndType(Uri.fromFile(new File(pathString)), "application/vnd.android.package-archive");
        install.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(install);
    }
}

posted @ 2014-11-27 17:50  云端止水  阅读(374)  评论(0编辑  收藏  举报