创建快捷图标
原理:
在看安卓上层源码的时候:桌面应用在Launcher2包中E:\系统上层所有应用的源代码\Launcher2
(安卓系统的默认桌面也是一个手机应用程序)
查看源码可知,在Launcher2的清单文件中注册了一个广播接受者 (见附录)
卸载桌面应用:
在shell模式下卸载系统的桌面应用
过程:cd /system/app------>ls可以看到Launch2.apk------------->mount -o remount rw /system--------->rm -r Launch2.apk--------->桌面就没有了
附录一:Launcher2的<recevier>
<!-- Intent received used to install shortcuts from other applications --><receiverandroid:name="com.android.launcher2.InstallShortcutReceiver"android:permission="com.android.launcher.permission.INSTALL_SHORTCUT"><intent-filter><action android:name="com.android.launcher.action.INSTALL_SHORTCUT" /></intent-filter></receiver><!-- Intent received used to uninstall shortcuts from other applications --><receiverandroid:name="com.android.launcher2.UninstallShortcutReceiver"android:permission="com.android.launcher.permission.UNINSTALL_SHORTCUT"><intent-filter><action android:name="com.android.launcher.action.UNINSTALL_SHORTCUT" /></intent-filter></receiver>
附录二:创建快捷图标的事例源码:
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void createShortcut(View view){ //1.调用系统的提供的创建快捷方式的功能 Intent intent = new Intent(); intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); //2.给快捷方式设置名称 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "女神求救神器"); //3.给快捷方式设置图标 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.safe)); //4.设置快捷方式的功能 Intent c = new Intent(); c.setAction(Intent.ACTION_CALL); c.setData(Uri.parse("tel:110")); //添加快捷方式功能的意图 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, c); //5.调用系统提供的创建快捷方式的意图 sendBroadcast(intent); }}
注:需要权限 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}public void createShortcut(View view){//1.调用系统的提供的创建快捷方式的功能Intent intent = new Intent();intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");//2.给快捷方式设置名称intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "女神求救神器");//3.给快捷方式设置图标intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.safe));//4.设置快捷方式的功能Intent c = new Intent();c.setAction(Intent.ACTION_CALL);c.setData(Uri.parse("tel:110"));//添加快捷方式功能的意图intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, c);//5.调用系统提供的创建快捷方式的意图sendBroadcast(intent);}}
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

浙公网安备 33010602011771号