繁体   English   中英

适用于多种口味应用程序的Android App动态快捷方式

[英]Android App dynamic Shortcut for multi flavour app

您能帮忙为Android中的动态快捷方式配置应用程序包吗?

应用程序代码通过build.gradle使用产品调味料进行品牌 标记

productFlavors {
    branda {
        applicationId "com.bb.branda"
        ...
    }
    brandb {
        applicationId "com.bb.brandb"
        ...
    }
    ...
    ...

}

对于静态快捷方式 ,可以在shortcuts.xml文件中的“ targetPackage”标签下对其进行配置。

例如。 android:targetPackage =“ com.bb.branda”

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
<shortcut
    android:shortcutId="contact_us"
    android:enabled="true"
    android:icon="@drawable/home_contactus_icon"
    android:shortcutShortLabel="@string/label.contactus"
    android:shortcutLongLabel="@string/label.contactus"
    >
    <intent
        android:action="contactus"
        android:targetPackage="com.bb.brand"
        android:targetClass="com.bb.launcher.LauncherActivity"
        />
    <categories android:name="android.shortcut.conversation" />
</shortcut>

对于动态快捷方式 ,下面的代码片段在哪里可以做相同的事情?

 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {

        ShortcutManager shortcutManager = ctx.getSystemService(ShortcutManager.class);

        ShortcutInfo shortcut = new ShortcutInfo.Builder(ctx, shortcutId)
                .setShortLabel(sTitle)
                .setLongLabel(sTitle)
                .setIcon(Icon.createWithResource(ctx, resID))
                .setIntent(new Intent(sIntentAction))
                .build();

        shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
    }

提前致谢。

如果要实现的是指定意图包,则可以通过以下方式创建意图:

    Intent intent = new Intent(sIntentAction);
    intent.setComponent(new ComponentName("your.package.id", YourActivity.class.getName()));
    ShortcutInfo shortcut = new ShortcutInfo.Builder(ctx, shortcutId)
            .setShortLabel(sTitle)
            .setLongLabel(sTitle)
            .setIcon(Icon.createWithResource(ctx, resID))
            .setIntent(intent)
            .build();    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM