I have ended up using a Url Scheme
, for this task, more information can be found here:
And the code is, in my Manifest file in the main Activity I provided the following intent-filter:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="com.myhost" />
</intent-filter>
And in the activity it self I do this:
Intent intent = getIntent();
String value = null;
if (intent.getData() != null)
{
value = intent.getData().getQueryParameter("server");
}
if (value != null)
{
Log.d(TAG, "with scheme value: "+ value);
if (value.equals("my_test_server_address"))
{
Toast.makeText(this, "Server set to Test" , Toast.LENGTH_LONG).show();
}
else if (value.equals("my_production_server_address"))
{
Toast.makeText(this, "Server set to Production" , Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(this, "Server set to Address: "+ value , Toast.LENGTH_LONG).show();
}
Consts.BASE_URL = Uri.parse(value);
}
else
{
Log.d(TAG, "value was null");
}
Finally to start you application with this intent filter you need to create an HTML file, with the following code:
<a href="myapp://com.myhost?server=my_test_server_address">test</a>
<a href="myapp://com.myhost?server=my_production_server_address">production</a>