Reputation: 637
using following code in gradle we can switch between production and staging by changing in build variants tab.
productFlavors {
staging {
applicationId = "co.example.staging";
}
production {
applicationId = "co.example.production";
}
}
I want a code to switch between production and staging in the beginning of application. With two radio buttons to switch between production and staging(using xml file). Is it possible to do like this?.
Upvotes: 1
Views: 963
Reputation: 4611
In your gradle file, you can have a staging buildType not necessarily a flavor.
staging {
initWith debug
manifestPlaceholders = [hostName:"internal.example.com"]
applicationIdSuffix ".debugStaging"
}
then you can check in code using
if (BuildConfig.BUILD_TYPE == "staging") {
... do something...
}
if you want to check flavor
if (BuildConfig.FLAVOR == "staging") {
... do something...
}
Upvotes: 0
Reputation: 6251
like this:
in application
String getPhotoUrl() {
if(istest){
retrun "http://"
}else{
retrun "192.168.15.89"
}
}
boolean istest = false;
in activity:
btn.setOnClick(v->{
istest = !istest;
}
})
Upvotes: 0
Reputation: 6251
u cant. once the application is packaged,its applicationId is decided;
Upvotes: 0
Reputation: 1455
if you have debug option in staging. Check the debug flag using
boolean isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
if (isDebuggable) {
// perform code for staging
} else {
// perform code for production.
}
Upvotes: 1