<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name));
shortcutIntent.putExtra("duplicate", false);
Intent intent = new Intent();
intent.setComponent(new ComponentName(getPackageName(), MainActivity.class.getName()));
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
sendBroadcast(shortcutIntent); public class BootReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { //接收广播:系统启动完成后运行程序 if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { Intent newIntent = new Intent(context, searchDemo.class); 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_ADDED")) { String packageName = intent.getDataString().substring(8); System.out.println("---------------" + packageName); Intent newIntent = new Intent(); newIntent.setClassName(packageName,packageName+ ".searchDemo"); newIntent.setAction("android.intent.action.MAIN"); newIntent.addCategory("android.intent.category.LAUNCHER"); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(newIntent); } //接收广播:设备上删除了一个应用程序包。 :这个貌似需要root权限 <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/> if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
String ACTION_UNINSTALL_SHORTCUT ="com.android.launcher.action.UNINSTALL_SHORTCUT";
Intent intent3 = new Intent(ACTION_UNINSTALL_SHORTCUT );
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, R.string.app_name);
// 要删除的应用程序的ComponentName,即应用程序包名+activity的名字
ComponentName comp = new ComponentName("搜索","searchDemo");
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent()
.setComponent(comp).setAction("android.intent.action.MAIN"));
context.sendBroadcast(intent); } }

更多相关文章

  1. ch024 Android(安卓)BroadCastReceiver
  2. 你的手机到底安不安全?看看Android和iOS是如何防御恶意应用的吧
  3. Android(安卓)6.0棉花糖新特性,
  4. Android(安卓)Socket 发送广播包的那些坑
  5. Android(安卓)Socket 发送广播包的那些坑
  6. Android(安卓)月活跃人数超过10亿用户了,我却审美疲劳了
  7. android权限机制,你真的了解么
  8. 在Android平台上开发移动应用程序(毕业设计_外文翻译)
  9. android自学笔记 开始--->第一个应用--->第一个项目

随机推荐

  1. android Gridview生成程序快捷键的简单方
  2. Android--LowMemoryKiller知识点补充
  3. Android任务和返回栈完全解析,细数那些你
  4. android画了一个笑脸
  5. 架构
  6. android GPS定位和卫星个数(源码)
  7. Android——实现清除应用缓存功能
  8. Android 开发常用代码片段
  9. android studio gradle 两种更新方法更新
  10. 实现Android图片圆角