创建快捷图标

原理:

在看安卓上层源码的时候:桌面应用在Launcher2包中E:\系统上层所有应用的源代码\Launcher2
(安卓系统的默认桌面也是一个手机应用程序)
查看源码可知,在Launcher2的清单文件中注册了一个广播接受者  (见附录)

卸载桌面应用:

在shell模式下卸载系统的桌面应用
过程:cd  /system/app------>ls可以看到Launch2.apk------------->mount -o remount rw /system--------->rm -r Launch2.apk--------->桌面就没有了


附录一:Launcher2的<recevier>
  1. <!-- Intent received used to install shortcuts from other applications -->
  2. <receiver
  3. android:name="com.android.launcher2.InstallShortcutReceiver"
  4. android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
  5. <intent-filter>
  6. <action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
  7. </intent-filter>
  8. </receiver>
  9. <!-- Intent received used to uninstall shortcuts from other applications -->
  10. <receiver
  11. android:name="com.android.launcher2.UninstallShortcutReceiver"
  12. android:permission="com.android.launcher.permission.UNINSTALL_SHORTCUT">
  13. <intent-filter>
  14. <action android:name="com.android.launcher.action.UNINSTALL_SHORTCUT" />
  15. </intent-filter>
  16. </receiver>
附录二:创建快捷图标的事例源码:
  1. public class MainActivity extends Activity {
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. setContentView(R.layout.activity_main);
  6. }
  7. public void createShortcut(View view){
  8. //1.调用系统的提供的创建快捷方式的功能
  9. Intent intent = new Intent();
  10. intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
  11. //2.给快捷方式设置名称
  12. intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "女神求救神器");
  13. //3.给快捷方式设置图标
  14. intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.safe));
  15. //4.设置快捷方式的功能
  16. Intent c = new Intent();
  17. c.setAction(Intent.ACTION_CALL);
  18. c.setData(Uri.parse("tel:110"));
  19. //添加快捷方式功能的意图
  20. intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, c);
  21. //5.调用系统提供的创建快捷方式的意图
  22. sendBroadcast(intent);
  23. }
  24. }
注:需要权限
  1. <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>





posted @ 2015-01-29 21:27  就不呵呵呵  阅读(231)  评论(0编辑  收藏  举报