how do i make Activity intentFilter action dynamic from strings.xml












0















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");
context.startActivity(intent);
dynamic. But I'm not sure how can I do this.



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.










share|improve this question























  • Just curious to know, why can't you maintain separate manifest files for each flavors?

    – Kavin Prabhu
    Jan 2 at 11:10
















0















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");
context.startActivity(intent);
dynamic. But I'm not sure how can I do this.



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.










share|improve this question























  • Just curious to know, why can't you maintain separate manifest files for each flavors?

    – Kavin Prabhu
    Jan 2 at 11:10














0












0








0


3






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");
context.startActivity(intent);
dynamic. But I'm not sure how can I do this.



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.










share|improve this question














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");
context.startActivity(intent);
dynamic. But I'm not sure how can I do this.



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)/>






android action intentfilter android-productflavors






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 11:03









HAXMHAXM

1,91721521




1,91721521













  • 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

















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












1 Answer
1






active

oldest

votes


















3














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





share|improve this answer
























  • 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 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











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
});


}
});














draft saved

draft discarded


















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









3














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





share|improve this answer
























  • 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 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
















3














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





share|improve this answer
























  • 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 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














3












3








3







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





share|improve this answer













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






share|improve this answer












share|improve this answer



share|improve this answer










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 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



















  • 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 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

















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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter