Dynamic webview.loadUrl question?

  • Replies:1
Julie Carming
  • Forum posts: 1

Jul 5, 2012, 1:26:00 PM via Website

I am still learning, and my development experience is next to nothing, but in the current Eclipse project I am working on, there is one call that is being made to a static website address:

Example: webview.loadUrl("http://sampledomain.com/EN-US-com_company_appname/");

I would like to retrieve the variables above from the user's phone based on the following structure:

var1 = the android phone user language (ISO 2-digit code I suppose??)
var2 = the user's location (country - ISO 2-digit code I suppose??)
var3 = the application's package with underscores instead of periods

So it would ultimately end up looking something like this:

webview.loadUrl("http://sampledomain.com/var1-var2-var3/");

The application asks for all kinds of permissions in the manifest (see below) so I am sure that I would have access to make this happen, I just don't know how?

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.VIBRATE" />

Your help / advice would be greatly appreciated!

Reply
Jeremiah
  • Forum posts: 775

Jul 5, 2012, 6:47:28 PM via Website

Use the java.util.Locale api for getting the language and country.
http://developer.android.com/reference/java/util/Locale.html
Use Locale.getDefault ().getCountry() and Locale.getDefault().getLanguage();

If you need more specific location than country you could use the gps.
http://developer.android.com/reference/android/location/LocationManager.html
and
http://developer.android.com/reference/android/location/Location.html

For the application's package I don't know why you would need to programatically get this since you define the package in the application when you create it. Just also define a string with the package name you specified when creating the app.

static final String packageName = "com_my_package_name";

Reply