自启动apk,不是开机自启动apk 在A.apk中通过代码安装B.apk,我想实现:在B.apk安装完成后,自动启动B.apk,如何实现???开机自动运行apk,倒是监听下启动完成的消息就行了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 有难度有一个思路是监听PACKAGE_ADDED,但经测试,此action在xml中静态注册无效,同求解... 没试过,但应该是监听Intent。 监听这个apk安装完毕的消息不行吗 只要在A.apk进程没被关闭的情况下,A.apk中监听PACKAGE的广播,从A.apk中去启动B.apk还是可以的。 楼上兄弟,PACKAGE的广播,具体是啥值? android.intent.action.PACKAGE_ADDED接收这个广播if(Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())){ Toast.makeText(context, "有应用被添加", Toast.LENGTH_LONG).show(); }然后接收到之后去启动 我想我这话说得不好,自己总结如下: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> 我觉得 你可以去看看 pacakage的 一个service, 然后在里面添加 包广播 可能是可以实现的 监听PACKAGE_ADDED 我试过 也监听不到 如何在Service中写notification 求助,一个关于WebView的问题 如何获取虚拟键盘弹下的事件 系统应用程序 求助:怎样实现收发消息时繁简体转换? 关于java的一个算法问题,求高手 Button android:id 语法问题 跳转到Intent.ACTION_ALL_APPS出错 自定义RadioButton样式的问题 转租房子 像素问题 请问哪里有开放的流媒体播放的api,最好是rtsp协议的,其他的也可以
if(Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction())){
Toast.makeText(context, "有应用被添加", Toast.LENGTH_LONG).show();
}然后接收到之后去启动
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>