zoukankan      html  css  js  c++  java
  • 创建桌面快捷方式的实现

    创建桌面快捷方式:

    //创建快捷方式
        private void installShortcut() {
            //        <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>
            //快捷方式只能创建一次
            boolean installed = PrefUtils.getBoolean(this,"shortcut_installed", false);
            if (!installed) {
                //发一个广播
                Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
                //图标
                intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, BitmapFactory.decodeResource(getResources(),
                        R.mipmap.ic_launcher));//BitmapFactory: 将资源文件id转成Bitmap对象
                //名称
                intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "快捷测试");
                //动作
                Intent actionIntent = new Intent();
                //跳到主页面, 隐式意图 action
                actionIntent.setAction("com.loaderman.demo");
                actionIntent.addCategory(Intent.CATEGORY_DEFAULT);
                intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
                sendBroadcast(intent);
                PrefUtils.putBoolean(this, "shortcut_installed", true);
            }
    
        }
    public class PrefUtils {
    
        public static void putBoolean(Context ctx, String key, boolean value) {
            SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE);
            sp.edit().putBoolean(key, value).commit();
        }
    
        public static boolean getBoolean(Context ctx, String key, boolean defValue) {
            SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE);
            return sp.getBoolean(key, defValue);
        }
    }
    

     在清单文件添加权限和创建配置需要跳转界面的action

     <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
    
     <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                     <action android:name="com.loaderman.demo" />
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
     </activity>
    

     当此方法调用时就会去创建快捷方式.现在开发中很少使用

  • 相关阅读:
    汉明距离
    滑动窗口最大值
    go 携程池限制并发
    【动态UAC权限】无盾程序(win32&cmd)
    屏幕录像专家 爆破注册机 源码
    小程序蒙层滚动禁止穿透,在元素上面添加一个空函数catchtouchmove=preventTouchMove即可
    2021-01-08(今日笔记)
    css 文本超出以省略号显示 与 文本换行
    公众号平台获取关注用户openid列表记
    le5le-topology开发纪要
  • 原文地址:https://www.cnblogs.com/loaderman/p/6509839.html
Copyright © 2011-2022 走看看