虚位以待(AD)
虚位以待(AD)
首页 > 软件编程 > Android编程 > android直接创建桌面快捷方式

android直接创建桌面快捷方式
类别:Android编程   作者:码皇   来源:互联网   点击:

通过launcher源码可以看到创建快捷方式是通过- <receiver android:name="com android launcher2 InstallShortcutReceiver" android:permission="com android launcher permission INSTALL_SHORTCUT">- <inte
通过launcher源码可以看到创建快捷方式是通过
- <receiver android: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>
生成快捷方式
我们可以在程序启动时直接发送广播创建桌面快捷方式
 private void createShortCut(){
        Intent intent=new Intent("com.android.launcher.action.INSTALL_SHORTCUT");//action
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));//快捷方式名字
        intent.putExtra("duplicate", false); //是否重复创建快捷方式
        Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);//icon
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , BatteryProfile.class)); //启动界面
        sendBroadcast(intent);//发送广播
    }
我们需要在在mainfest.xml加入以下权限
  <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>


摘自  android 开发专栏
相关热词搜索: android 直接 创建