how do i make Activity intentFilter action dynamic from strings.xml
I'm using different product flavours, and opening an Activity through intentFilter whose action is predefined as shown below.
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.package.name.MyAction"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
For opening this activity I'm using :
Intent intent = new Intent("com.package.name.MyAction");
startActivity(intent);
Now, if my device have both product flavour apk, a chooser is coming for some device to open which activity app, for some devices it show a error no app found to perform the action
.
As soon as I uninstall one app, and keep only one app in my device everything works fine.
One solution I thought to overcome is, to make the action constant as Intent intent = new Intent("com.package.name.MyAction");
dynamic. But I'm not sure how can I do this.
context.startActivity(intent);
Im AndroidManifest, it should be something as:
<action android:name="com.package.name.MyAction"+getString(R.string.product_name)/>
This is the part where I'm unable to get the string in AndroidMaifest
.
For opening the activity I have done:
Intent intent = new Intent("com.package.name.MyAction"+getString(R.string.product_name));
startActivity(intent);
Any help will be appreciated, thank you.

add a comment |
I'm using different product flavours, and opening an Activity through intentFilter whose action is predefined as shown below.
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.package.name.MyAction"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
For opening this activity I'm using :
Intent intent = new Intent("com.package.name.MyAction");
startActivity(intent);
Now, if my device have both product flavour apk, a chooser is coming for some device to open which activity app, for some devices it show a error no app found to perform the action
.
As soon as I uninstall one app, and keep only one app in my device everything works fine.
One solution I thought to overcome is, to make the action constant as Intent intent = new Intent("com.package.name.MyAction");
dynamic. But I'm not sure how can I do this.
context.startActivity(intent);
Im AndroidManifest, it should be something as:
<action android:name="com.package.name.MyAction"+getString(R.string.product_name)/>
This is the part where I'm unable to get the string in AndroidMaifest
.
For opening the activity I have done:
Intent intent = new Intent("com.package.name.MyAction"+getString(R.string.product_name));
startActivity(intent);
Any help will be appreciated, thank you.

Just curious to know, why can't you maintain separatemanifest
files for each flavors?
– Kavin Prabhu
Jan 2 at 11:10
add a comment |
I'm using different product flavours, and opening an Activity through intentFilter whose action is predefined as shown below.
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.package.name.MyAction"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
For opening this activity I'm using :
Intent intent = new Intent("com.package.name.MyAction");
startActivity(intent);
Now, if my device have both product flavour apk, a chooser is coming for some device to open which activity app, for some devices it show a error no app found to perform the action
.
As soon as I uninstall one app, and keep only one app in my device everything works fine.
One solution I thought to overcome is, to make the action constant as Intent intent = new Intent("com.package.name.MyAction");
dynamic. But I'm not sure how can I do this.
context.startActivity(intent);
Im AndroidManifest, it should be something as:
<action android:name="com.package.name.MyAction"+getString(R.string.product_name)/>
This is the part where I'm unable to get the string in AndroidMaifest
.
For opening the activity I have done:
Intent intent = new Intent("com.package.name.MyAction"+getString(R.string.product_name));
startActivity(intent);
Any help will be appreciated, thank you.

I'm using different product flavours, and opening an Activity through intentFilter whose action is predefined as shown below.
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.package.name.MyAction"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
For opening this activity I'm using :
Intent intent = new Intent("com.package.name.MyAction");
startActivity(intent);
Now, if my device have both product flavour apk, a chooser is coming for some device to open which activity app, for some devices it show a error no app found to perform the action
.
As soon as I uninstall one app, and keep only one app in my device everything works fine.
One solution I thought to overcome is, to make the action constant as Intent intent = new Intent("com.package.name.MyAction");
dynamic. But I'm not sure how can I do this.
context.startActivity(intent);
Im AndroidManifest, it should be something as:
<action android:name="com.package.name.MyAction"+getString(R.string.product_name)/>
This is the part where I'm unable to get the string in AndroidMaifest
.
For opening the activity I have done:
Intent intent = new Intent("com.package.name.MyAction"+getString(R.string.product_name));
startActivity(intent);
Any help will be appreciated, thank you.
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.package.name.MyAction"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.package.name.MyAction"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<action android:name="com.package.name.MyAction"+getString(R.string.product_name)/>
<action android:name="com.package.name.MyAction"+getString(R.string.product_name)/>


asked Jan 2 at 11:03


HAXMHAXM
1,91721521
1,91721521
Just curious to know, why can't you maintain separatemanifest
files for each flavors?
– Kavin Prabhu
Jan 2 at 11:10
add a comment |
Just curious to know, why can't you maintain separatemanifest
files for each flavors?
– Kavin Prabhu
Jan 2 at 11:10
Just curious to know, why can't you maintain separate
manifest
files for each flavors?– Kavin Prabhu
Jan 2 at 11:10
Just curious to know, why can't you maintain separate
manifest
files for each flavors?– Kavin Prabhu
Jan 2 at 11:10
add a comment |
1 Answer
1
active
oldest
votes
In your build.gradle
(app), config your flavors like this:
productFlavors {
first {
// ...
manifestPlaceholders = [action: "com.package.name.ActionA"]
}
second {
// ...
manifestPlaceholders = [action: "com.package.name.ActionB"]
}
}
Then place the value of placeholder in AndroidManifest.xml
file:
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="${action}"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
In order to get the placeholder to open the activity, just get it through BuildConfig
:
String yourAction = BuildConfig.action;
// start your intent here
Yeah this will do. More info at developer.android.com/studio/build/manifest-build-variables
– Kavin Prabhu
Jan 2 at 11:21
1
@nhp this really helped thanks, However I find @kavin link more useful, so I have used that, since in my flavour I was already using applicationId, so instead adding aaction
field, I used thatapplicationId
. Thanks @kavin and @nhp appreciated your help.
– HAXM
Jan 2 at 11:38
I'm glad it helped you out. Roger that the combination of application and other placeholders too ^^
– nhp
Jan 7 at 8:37
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005165%2fhow-do-i-make-activity-intentfilter-action-dynamic-from-strings-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your build.gradle
(app), config your flavors like this:
productFlavors {
first {
// ...
manifestPlaceholders = [action: "com.package.name.ActionA"]
}
second {
// ...
manifestPlaceholders = [action: "com.package.name.ActionB"]
}
}
Then place the value of placeholder in AndroidManifest.xml
file:
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="${action}"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
In order to get the placeholder to open the activity, just get it through BuildConfig
:
String yourAction = BuildConfig.action;
// start your intent here
Yeah this will do. More info at developer.android.com/studio/build/manifest-build-variables
– Kavin Prabhu
Jan 2 at 11:21
1
@nhp this really helped thanks, However I find @kavin link more useful, so I have used that, since in my flavour I was already using applicationId, so instead adding aaction
field, I used thatapplicationId
. Thanks @kavin and @nhp appreciated your help.
– HAXM
Jan 2 at 11:38
I'm glad it helped you out. Roger that the combination of application and other placeholders too ^^
– nhp
Jan 7 at 8:37
add a comment |
In your build.gradle
(app), config your flavors like this:
productFlavors {
first {
// ...
manifestPlaceholders = [action: "com.package.name.ActionA"]
}
second {
// ...
manifestPlaceholders = [action: "com.package.name.ActionB"]
}
}
Then place the value of placeholder in AndroidManifest.xml
file:
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="${action}"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
In order to get the placeholder to open the activity, just get it through BuildConfig
:
String yourAction = BuildConfig.action;
// start your intent here
Yeah this will do. More info at developer.android.com/studio/build/manifest-build-variables
– Kavin Prabhu
Jan 2 at 11:21
1
@nhp this really helped thanks, However I find @kavin link more useful, so I have used that, since in my flavour I was already using applicationId, so instead adding aaction
field, I used thatapplicationId
. Thanks @kavin and @nhp appreciated your help.
– HAXM
Jan 2 at 11:38
I'm glad it helped you out. Roger that the combination of application and other placeholders too ^^
– nhp
Jan 7 at 8:37
add a comment |
In your build.gradle
(app), config your flavors like this:
productFlavors {
first {
// ...
manifestPlaceholders = [action: "com.package.name.ActionA"]
}
second {
// ...
manifestPlaceholders = [action: "com.package.name.ActionB"]
}
}
Then place the value of placeholder in AndroidManifest.xml
file:
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="${action}"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
In order to get the placeholder to open the activity, just get it through BuildConfig
:
String yourAction = BuildConfig.action;
// start your intent here
In your build.gradle
(app), config your flavors like this:
productFlavors {
first {
// ...
manifestPlaceholders = [action: "com.package.name.ActionA"]
}
second {
// ...
manifestPlaceholders = [action: "com.package.name.ActionB"]
}
}
Then place the value of placeholder in AndroidManifest.xml
file:
<activity android:name=".MyActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="${action}"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
In order to get the placeholder to open the activity, just get it through BuildConfig
:
String yourAction = BuildConfig.action;
// start your intent here
answered Jan 2 at 11:15
nhpnhp
2,019416
2,019416
Yeah this will do. More info at developer.android.com/studio/build/manifest-build-variables
– Kavin Prabhu
Jan 2 at 11:21
1
@nhp this really helped thanks, However I find @kavin link more useful, so I have used that, since in my flavour I was already using applicationId, so instead adding aaction
field, I used thatapplicationId
. Thanks @kavin and @nhp appreciated your help.
– HAXM
Jan 2 at 11:38
I'm glad it helped you out. Roger that the combination of application and other placeholders too ^^
– nhp
Jan 7 at 8:37
add a comment |
Yeah this will do. More info at developer.android.com/studio/build/manifest-build-variables
– Kavin Prabhu
Jan 2 at 11:21
1
@nhp this really helped thanks, However I find @kavin link more useful, so I have used that, since in my flavour I was already using applicationId, so instead adding aaction
field, I used thatapplicationId
. Thanks @kavin and @nhp appreciated your help.
– HAXM
Jan 2 at 11:38
I'm glad it helped you out. Roger that the combination of application and other placeholders too ^^
– nhp
Jan 7 at 8:37
Yeah this will do. More info at developer.android.com/studio/build/manifest-build-variables
– Kavin Prabhu
Jan 2 at 11:21
Yeah this will do. More info at developer.android.com/studio/build/manifest-build-variables
– Kavin Prabhu
Jan 2 at 11:21
1
1
@nhp this really helped thanks, However I find @kavin link more useful, so I have used that, since in my flavour I was already using applicationId, so instead adding a
action
field, I used that applicationId
. Thanks @kavin and @nhp appreciated your help.– HAXM
Jan 2 at 11:38
@nhp this really helped thanks, However I find @kavin link more useful, so I have used that, since in my flavour I was already using applicationId, so instead adding a
action
field, I used that applicationId
. Thanks @kavin and @nhp appreciated your help.– HAXM
Jan 2 at 11:38
I'm glad it helped you out. Roger that the combination of application and other placeholders too ^^
– nhp
Jan 7 at 8:37
I'm glad it helped you out. Roger that the combination of application and other placeholders too ^^
– nhp
Jan 7 at 8:37
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005165%2fhow-do-i-make-activity-intentfilter-action-dynamic-from-strings-xml%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Just curious to know, why can't you maintain separate
manifest
files for each flavors?– Kavin Prabhu
Jan 2 at 11:10