相关疑难解决方法(0)

如何将应用程序的快捷方式添加到主屏幕

我知道它没有记录,也不适用于所有设备,但我看到越来越多的应用程序在安装后将其快捷方式放在主屏幕上.发现一堆代码块如何做到但对我来说它们并不适合.这就是我现在所得到的.

  1. 需要清单中的权限.

    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
    
    Run Code Online (Sandbox Code Playgroud)
  2. 创建应该调用的活动的Intent.Ex(来自cgeek):

    Intent shortcutIntent = new Intent();
    shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    
    Run Code Online (Sandbox Code Playgroud)
  3. 创建快捷方式

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
    
    Run Code Online (Sandbox Code Playgroud)

我的问题是:在安装.apk后,这段代码应该去哪里添加快捷方式?我在启动器活动中尝试了此代码,每次应用启动时都会创建损坏的(另一个故事)快捷方式.

android shortcut android-3.0-honeycomb

20
推荐指数
1
解决办法
2万
查看次数

如何在启动器主屏幕上放置应用程序图标?

如您所知,当正常安装应用程序时,会在启动器菜单屏幕上创建图标.我想要做的是在安装过程中在用户主屏幕上创建图标.(不按图标5秒钟.)

我从另一个来源听到这个只是添加

<category android:value="android.intent.category.HOME" />
Run Code Online (Sandbox Code Playgroud)

到AndroidManifest.xml文件,但它没有用.

还有其他办法吗?

android

16
推荐指数
3
解决办法
3万
查看次数

标签 统计

android ×2

android-3.0-honeycomb ×1

shortcut ×1