android - 每种应用风格的自定义 Intent ?

标签 android android-intent

假设我有应用 A 和 B。应用 B 有多种构建风格,但每一种都略有不同,我想从应用 A 启动特定的风格。

我考虑过使用一个自定义共享 Intent ,但我不希望操作系统在用户安装了多个版本的 B 时提示用户使用哪个版本来处理 Intent 。

是否可以通过编程方式为应用程序的每种风格定义独特的自定义 Intent ?

最佳答案

为了在多个风格之间使用一个共享的 AndroidManifest 并为每个风格都有独特的 Intent ,我在 build.gradle 中为每个风格添加了一个 list 占位符

default {
    manifestPlaceholders = [uriPrefix: "myprefix"]
}
someFlavor{
    manifestPlaceholders = [uriPrefix: "otherprefix"]
}

在 AndroidManfest.xml 中使用 list 占位符,就像在 Intent 过滤器中一样:

        <intent-filter>
            <action android:name="com.custom.app.${uriPrefix}.SOME_ACTION" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="${uriPrefix}" />
        </intent-filter>

关于android - 每种应用风格的自定义 Intent ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39007649/

相关文章:

javascript - 在Webview/UIWebView中加载外部URL时,是否可以加载本地JS文件?

android - 应用已在 Google Play 上发布,但无法使用 Google 语音操作

android - 以编程方式打开特定的设置页面

android - 分享 Intent 不适用于 Facebook Messenger

java - 将字符串传递给其他 Activity 不起作用

android - 在 Android 的线程中运行 ProgressDialog

android - 通过 View 模型和使用工厂创建 View 模型之间的区别?

android - Android Studio错误: java.net.SocketException: Connection reset

php - 验证传入的注册数据

Android:了解 Intent 过滤器