android 创建桌面快捷键

      如何判断快捷方式是否已经创建的方法,因为快捷方式信息是保存在com.android.launcher的launcher.db的favorites表中,所以可以查询此表得到


一般android应用程序安装完成后是不会自动创建快捷方式的,所以可以自己在程序启动时实现。


需要权限
  和要点击快捷方式对应的那个activity的属性。


  以下是代码片段:


<intent-filter>
    <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
    <intent-filter>
    <action android:name="android.intent.action.CREATE_SHORTCUT"></action>
</intent-filter>






       如何判断快捷方式是否已经创建的方法,因为快捷方式信息是保存在com.android.launcher的launcher.db的favorites表中,所以可以查询此表得到,


    public boolean isAddShortCut() {


        boolean isInstallShortcut = false;
        final ContentResolver cr = this.getContentResolver();


        int versionLevel = android.os.Build.VERSION.SDK_INT;
        String AUTHORITY = "com.android.launcher2.settings";
        
        //2.2以上的系统的文件文件名字是不一样的
        if (versionLevel >= 8) {
            AUTHORITY = "com.android.launcher2.settings";
        } else {
            AUTHORITY = "com.android.launcher.settings";
        }


        final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
                + "/favorites?notify=true");
        Cursor c = cr.query(CONTENT_URI,
                new String[] { "title", "iconResource" }, "title=?",
                new String[] { getString(R.string.app_name) }, null);


        if (c != null && c.getCount() > 0) {
            isInstallShortcut = true;
        }
        return isInstallShortcut;
    }






  添加快捷方式:
    public void addShortCut(){
        
        Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
        // 设置属性
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
        ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this.getApplicationContext(), R.drawable.icon);
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON,iconRes);
 
        // 是否允许重复创建
        shortcut.putExtra("duplicate", false);
        
        //设置桌面快捷方式的图标
        Parcelable icon = Intent.ShortcutIconResource.fromContext(this,R.drawable.icon);        
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,icon);
        
        //点击快捷方式的操作
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        intent.setClass(AddShortCutActivity.this, AddShortCutActivity.class);
        
        // 设置启动程序
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
        
        //广播通知桌面去创建
        this.sendBroadcast(shortcut);
    }






上面的判断是否添加快捷方式和添加快捷方式都是在activity的onCreate()方法中被调用的。


        if(!isAddShortCut()){
            addShortCut();
        }










androidManifest.xml文件的片段


<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.shao.add"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
 
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".AddShortCutActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
              <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT"></action>
            </intent-filter>
        </activity>
 
    </application>
      <!-- 需要权限 -->
      <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
      <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
</manifest>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在 Windows 操作系统中,可以通过以下步骤在桌面创建 Android Studio 快捷方式: 1. 打开 Android Studio 软件。 2. 点击顶部菜单栏中的 "File"(文件)选项。 3. 选择 "Settings"(设置)选项。 4. 在弹出的窗口中,选择 "Appearance & Behavior"(外观和行为)。 5. 选择 "System Settings"(系统设置)。 6. 在下方的 "Startup/Shutdown"(启动/关闭)选项中,勾选 "Create Desktop Entry"(创建桌面条目)选项。 7. 点击 "OK" 保存设置并退出。 这样就可以在桌面上找到 Android Studio 的快捷方式并方便地启动软件了。 ### 回答2: android studio是一款针对安卓开发者的集成开发环境,操作灵活且功能强大。对于频繁使用android studio的开发者来说,将它添加到桌面快捷方式能够方便快捷地打开它。 具体来说,添加android studio到桌面快捷的方法如下: 1. 打开android studio,找到“File”(文件)菜单,选择“Create Desktop Entry”(创建桌面快捷方式)选项; 2. 在弹出的对话框中,“Name”(名称)一栏默认为“Android Studio”,你可根据需要自行修改; 3. 在执行该操作之前,请先安装正确的Gnome或KDE桌面环境。在ubuntu中,你需要安装gnome-panel或gnome-shell才能看到创建桌面启动程序。(需要root权限),例如:sudo apt-get install gnome-panel 4. 将“Create”(创建)选项选中,然后点击“OK”(确定)。 这样就完成了android studio创建桌面快捷的方法,之后你可以在桌面上看到一个新的图标,点击即可打开android studio了。若之前已经创建android studio的快捷方式,则可以直接在已有的快捷方式上右键修改图标和名称。 总而言之,通过添加到桌面快捷方式的方法,可以快速地打开android studio,提高工作效率,让开发者更加方便地进行移动应用开发。 ### 回答3: Android Studio是一款由Google官方推出的Android开发工具,它的出现大大简化了Android开发的流程,提高了开发效率,被广泛应用于各类Android应用的开发。在频繁开发Android项目的过程中,为了方便使用,将其创建桌面快捷方式是非常有帮助的。以下是关于Android Studio桌面快捷方式的相关介绍。 在Windows操作系统中,创建Android Studio桌面快捷方式非常简单。首先,我们需要在电脑上安装Android Studio软件,并在启动后打开主界面。接着,我们可以将鼠标光标移至创建快捷方式的位置,右键点击鼠标,在弹出的选项中选择“发送到桌面快捷方式”。此时,便可以在桌面上看到Android Studio的快捷方式了。如果希望进一步优化,还可以右键点击快捷方式,选择“属性”,在弹出的属性窗口中设置快捷键、改变图标等,以便更加方便地使用Android Studio。 在Mac OSX操作系统中,创建Android Studio桌面快捷方式的步骤也非常简单。首先,在启动Android Studio后打开主界面,然后点击“Android Studio”菜单,选择“偏好设置”,在弹出的菜单中选择“Keymaps”选项。在Keymaps选项中,我们可以自由设定Android Studio的快捷键。接着,我们可以按下“Command+Shift+A”键,打开全局搜索功能。在搜索框中输入“Create Desktop Entry”,然后点击“Create Desktop Entry”选项,即可在桌面创建Android Studio的快捷方式。如果需要更改桌面快捷方式的图标或名称,可以右键点击快捷方式图标,在弹出的选项中选择“图标和名称”,进行相应的修改。 总结来说,无论是在Windows系统还是Mac OSX系统中,使用Android Studio开发Android项目时都可以使用快捷方式来进一步提高效率。另外,通过对桌面快捷方式的改变,可以让开发者更加方便地使用Android Studio,从而提高开发效率。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值