Android:创建快捷方式
16lz
2021-01-23
- /**
- *创建快捷方式到Shortcut列表<br>
- *关联程序的<intent-filter>中添加:<actionandroid:name="android.intent.action.CREATE_SHORTCUT"/>
- */
- privatevoidaddShortcutToOptions(){
- Intentshortcut=newIntent(Intent.ACTION_CREATE_SHORTCUT);
- //不允许重建
- shortcut.putExtra("duplicate",false);
- //设置名字
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
- this.getString(R.string.app_name));
- //设置图标
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
- Intent.ShortcutIconResource.fromContext(this,
- R.drawable.ic_launcher));
- //设置意图和快捷方式关联的程序
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
- newIntent(this,this.getClass()));
- //发送消息队列
- setResult(RESULT_OK,shortcut);
- }
- /**
- *添加快捷方式到桌面要点:
- *1.给Intent指定action="com.android.launcher.INSTALL_SHORTCUT"
- *2.给定义为Intent.EXTRA_SHORTCUT_INENT的Intent设置与安装时一致的action(必须要有)
- *3.添加权限:com.android.launcher.permission.INSTALL_SHORTCUT
- */
- privatevoidaddShortcutToDesktop(){
- Intentshortcut=newIntent("com.android.launcher.action.INSTALL_SHORTCUT");
- //不允许重建
- shortcut.putExtra("duplicate",false);
- //设置名字
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,this.getString(R.string.app_name));
- //设置图标
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this,
- R.drawable.ic_launcher));
- //设置意图和快捷方式关联程序
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,newIntent(this,this.getClass()).setAction(Intent.ACTION_MAIN));
- //发送消息
- sendBroadcast(shortcut);
- }
- /**
- *添加权限:<uses-permissionandroid:name="com.android.launcher.permission.READ_SETTINGS"/>
- *
- *@return
- */
- privatebooleanhasInstallShortcut(){
- booleanhasInstall=false;
- finalStringAUTHORITY="com.android.launcher.settings";
- UriCONTENT_URI=Uri.parse("content://"+AUTHORITY
- +"/favorites?notify=true");
- Cursorcursor=this.getContentResolver().query(CONTENT_URI,
- newString[]{"title","iconResource"},"title=?",
- newString[]{this.getString(R.string.app_name)},null);
- if(cursor!=null&&cursor.getCount()>0){
- hasInstall=true;
- }
- returnhasInstall;
- }
更多相关文章
- android 创建快捷方式图标
- Android命令行启动程序正确使用技巧解析
- Android 程序优化
- 电子书 android高薪之路-android程序员面试宝典.pdf
- Android应用程序基础知识
- 详解android应用程序的反编译
- 高焕堂《android从程序员到架构师之路》 YY讲坛活动直面架构设计