0

I want to change application configuration for the connection server where I got two options: Test, Production. This is set using a static string inside of one of my Helper classes.

Now I want to make this change from outside the application, using another icon in the system. The reason for that is that I don't want the user be able to do so (And I don't want it to be a part of my application). Only the development team that has to check the application in the field could add this icon and make this change.

So I don't want to create some kind of widget that will get installed with my application.

Is there a way to do some thing like that? If so how can this be done? Should I make a whole new application for that?

Thanks.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187

2 Answers2

0

you can set this option in SharedPreferences and create an activity for the development team to set it, with the LAUNCHER option in the manifest, so it'll have a launch icon.

what you can do to hide it from your users is removing this activity from the manifest for release builds.

if you're using Android Studio / Gradle, you can use different AndroidManifest.xml for different build types, see How to tell Gradle to use a different AndroidManifest from the command line?

Community
  • 1
  • 1
Gal Ben-Haim
  • 17,433
  • 22
  • 78
  • 131
  • If I create two activities with the LAUNCHER intent-filter in the Manifest file it will create two launch icons that each leads to the specified activity of the same application? – Emil Adz Nov 19 '13 at 13:17
  • yes it will. Android creates an icon for each activity with the LAUNCHER category. read more about this here - http://developer.android.com/guide/components/intents-filters.html – Gal Ben-Haim Nov 19 '13 at 17:47
-1

I have ended up using a Url Scheme, for this task, more information can be found here:

android custom url scheme..?

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>
Community
  • 1
  • 1
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • you asked about adding additional icon to the launcher and got an answer for that, please mark it as accepted rather than marking your own answer which doesn't answer the question – Gal Ben-Haim Dec 08 '13 at 06:57
  • @GalBen-Haim, I asked about: "Change application configuration from outside the application", I also pointed out that: "And I don't want it to be a part of my application"... You solution maybe works for my question but I have to maintain it all the time.... on the other hand, with a URL Scheme I just added a shortcut to a web page on one of my desktops and it works great. So actually this is a better solution to what I was asking then you proposed.. Now, please remove the down-vote, there is no need to be mad. – Emil Adz Dec 08 '13 at 08:28