android直接创建桌面快捷方式
来源:互联网 发布:2站域名wwwtt69con 编辑:程序博客网 时间:2024/04/29 20:01
通过launcher源码可以看到创建快捷方式是通过
-<receiver android:name="com.android.launcher2.InstallShortcutReceiver" android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
- <intent-filter>
<actionandroid: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);//发送广播
}
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 创建桌面快捷方式
- Android 创建桌面快捷方式
- android创建桌面快捷方式
- Android 创建桌面快捷方式
- android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android创建桌面快捷方式
- android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android 创建桌面快捷方式
- Android:桌面创建快捷方式
- Android创建桌面快捷方式
- android 创建桌面快捷方式
- Android创建桌面快捷方式
- android 创建桌面快捷方式
- Android创建桌面快捷方式
- yii 基本流程结构
- 最常被程序员们谎称读过的计算机书籍
- 突发奇想:.net的Web开发新建的页面引用默认哪些命名空间以及它们大概的作用
- webwork中的xwork.xml配置常见错误
- hadoop中Map的输出文件命名与分片次序一致
- android直接创建桌面快捷方式
- Eclipse运行错误Failed to create the Java Virtual Machine解决方法
- 十三个球问题
- printf函数的一些理解
- linux 多线程编程
- 《把时间当作朋友》经典语句
- CSS之设置p段落中的文字与页面左侧缩进两个字符!...
- 学习实用英语(4)
- directshow filter 调试步骤