在A.apk中通过代码安装B.apk,我想实现:在B.apk安装完成后,自动启动B.apk,如何实现???
开机自动运行apk,倒是监听下启动完成的消息就行了。

解决方案 »

  1.   

    有难度有一个思路是监听PACKAGE_ADDED,但经测试,此action在xml中静态注册无效,同求解...
      

  2.   

    没试过,但应该是监听Intent。
      

  3.   

    监听这个apk安装完毕的消息不行吗
      

  4.   

    只要在A.apk进程没被关闭的情况下,A.apk中监听PACKAGE的广播,从A.apk中去启动B.apk还是可以的。
      

  5.   

    楼上兄弟,PACKAGE的广播,具体是啥值?
      

  6.   

    android.intent.action.PACKAGE_ADDED接收这个广播
    if(Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())){
                        Toast.makeText(context, "有应用被添加", Toast.LENGTH_LONG).show();
                       
                }然后接收到之后去启动
      

  7.   

    我想我这话说得不好,自己总结如下:
    1.在正规渠道下安装B.apk,对package的监听如果写在xml里,B.apk是监听不到自己安装成功时系统发出的package_added的action。但如果写在A.apk的xml里,A.apk是可以监听到B.apk的安装情况的。
    2.在真机调试下,写在xml里同样可以监听到B.apk的安装消息。(现在我也很感到奇怪...)1.建个BroadcastReceiver类package lab.sodino.appadded;import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.Toast;public class ApkReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) {
    Toast toast = Toast.makeText(context, intent.getAction(),Toast.LENGTH_LONG);
    toast.show();
    }
    }
    2.在代码中注册或在XML里注册监听器,这儿写出xml的情况:
    <receiver android:name="ApkReceiver">
    <intent-filter>
    <action android:name="android.intent.action.PACKAGE_ADDED"></action>
    <action android:name="android.intent.action.PACKAGE_CHANGED"></action>
    <action android:name="android.intent.action.PACKAGE_DATA_CLEARED"></action>
    <action android:name="android.intent.action.PACKAGE_INSTALL"></action>
    <action android:name="android.intent.action.PACKAGE_REMOVED"></action>
    <action android:name="android.intent.action.PACKAGE_REPLACED"></action>
    <action android:name="android.intent.action.PACKAGE_RESTARTED"></action>
    <data android:scheme="package"></data>
    </intent-filter>
    </receiver>
      

  8.   

    我觉得 你可以去看看 pacakage的 一个service,  然后在里面添加 包广播 可能是可以实现的
      

  9.   

    监听PACKAGE_ADDED  我试过 也监听不到