android apk安装结束的系统广播的监听
package com.lenovo.lsf.push.messagecenter.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//接收广播:系统启动完成后运行程序
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
}
//接收广播:设备上新安装了一个应用程序包后自动启动新安装应用程序。
if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
String packageName = intent.getDataString().substring(8);
System.out.println("---------------" + packageName);
PackageManager pageManage = context.getPackageManager();
Intent intent1 = pageManage.getLaunchIntentForPackage(packageName);
context.startActivity(intent1);
// Intent newIntent = new Intent();
// newIntent.setClassName(packageName,packageName+".MainActivity");
// newIntent.setAction("android.intent.action.MAIN");
// newIntent.addCategory("android.intent.category.LAUNCHER");
// newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(newIntent);
}
//接收广播:设备上删除了一个应用程序包。
if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
}
}
}
<receiver android:name="com.lenovo.lsf.push.messagecenter.receiver.BootReceiver"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package" />
<!-- 注意!! 这句必须要加,否则接收不到BroadCast -->
</intent-filter>
</receiver>
更多相关文章
- android内部类广播(本地广播)BroadcastReceiver的静态注册方法(Andr
- 【Android】【应用信息】获取服务列表
- Android重启应用程序代码
- android 杀进程方法
- Android(安卓)发送无序广播
- 调试Android第三方应用所需要的工具
- Android(安卓)获取已经安装的程序
- Android(安卓)O 为应用添加默认权限,进入应用时不需要请求 Permis
- android DatePickerDialog的应用举例