Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:在主屏幕上获取更多指向“我的包”中活动的图标(快捷方式)_Android_Launcher_Homescreen_Android Launcher_App Launcher - Fatal编程技术网

Android 安卓:在主屏幕上获取更多指向“我的包”中活动的图标(快捷方式)

Android 安卓:在主屏幕上获取更多指向“我的包”中活动的图标(快捷方式),android,launcher,homescreen,android-launcher,app-launcher,Android,Launcher,Homescreen,Android Launcher,App Launcher,我知道我可以创建一个可以放在主屏幕上的小部件,但是当用户安装应用程序时,是否有可能只有我的标准启动器图标会启动某个活动。但是,当用户选择这样做时(例如在我的应用程序中单击按钮),会在设备的主屏幕上创建另一个图标,直接链接到另一个活动?那么,通过单击主屏幕上的图标,我的程序包中的另一个活动将打开 如果可能的话,有人有一个片段吗 谢谢 感谢这个博客: 在清单中添加所需的权限: <uses-permission android:name="com.android.launcher.permiss

我知道我可以创建一个可以放在主屏幕上的小部件,但是当用户安装应用程序时,是否有可能只有我的标准启动器图标会启动某个活动。但是,当用户选择这样做时(例如在我的应用程序中单击按钮),会在设备的主屏幕上创建另一个图标,直接链接到另一个活动?那么,通过单击主屏幕上的图标,我的程序包中的另一个活动将打开

如果可能的话,有人有一个片段吗

谢谢

感谢这个博客:

在清单中添加所需的权限:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
然后使用以下方法安装/卸载快捷方式:

 private void addShortcut() {
        //Adding shortcut for MainActivity 
        //on Home screen
        Intent shortcutIntent = new Intent(getApplicationContext(),
                MainActivity.class);

        shortcutIntent.setAction(Intent.ACTION_MAIN);

        Intent addIntent = new Intent();
        addIntent
                .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                        R.drawable.ic_launcher));

        addIntent
                .setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        getApplicationContext().sendBroadcast(addIntent);
    }


private void removeShortcut() {

        //Deleting shortcut for MainActivity 
        //on Home screen
        Intent shortcutIntent = new Intent(getApplicationContext(),
                MainActivity.class);
        shortcutIntent.setAction(Intent.ACTION_MAIN);

        Intent addIntent = new Intent();
        addIntent
                .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");

        addIntent
                .setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
        getApplicationContext().sendBroadcast(addIntent);
    }
要将活动添加到快捷方式,只需将此意图过滤器添加到清单中的活动:

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

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