zoukankan      html  css  js  c++  java
  • Android 快捷方式相关操作

    尽管现在少数手机不支持快捷方式,但是仍然有大部分手机是支持的。创建快捷方式,可以减少用户在应用列表繁多的应用程序中查找应用的时间,快速进入应用;或是应用中的某个功能使用频率较高,创建快捷方式,可以快速使用此功能;

    自动创建快捷方式:

    1.添加快捷方式所需的权限:com.android.launcher.permission.INSTAL_SAHORTCUT

    1 <!--添加快捷方式需要的权限  -->  
    2 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> 

    2.生成快捷方式:

      /**
         * 为程序创建桌面快捷方式
         */
        private void addShortcut() {
    
            //向桌面添加快捷方式的Intent
            Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    
            // 快捷方式的名称
            shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    
            // 快捷方式的图标
            Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
            shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
    
            // 不允许重复创建
            shortcutIntent.putExtra("duplicate", false);
    
            // 设置待启动程序,页面相关参数
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            String pkgName = getPackageName();
            intent.setComponent(new ComponentName(pkgName, pkgName + "." + getLocalClassName()));
    
            // 快捷方式要启动的程序
            shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    
            // 发送创建广播
            sendBroadcast(shortcutIntent);
        }
  • 相关阅读:
    R-CNN学习笔记
    Numpy和Pandas
    用python解决打标签时将xml文件的标签名打错
    爬虫Ⅱ:scrapy框架
    爬虫Ⅰ:爬虫的基础知识
    Linux学习笔记
    MySql笔记Ⅱ
    MySql笔记Ⅰ
    Qt数据库报错:“Unable to execute statement”
    Qt数据库报错“out of memory Error opening database“
  • 原文地址:https://www.cnblogs.com/pillowzhou/p/4874375.html
Copyright © 2011-2022 走看看