:::: MENU ::::
Browsing posts in: Java (Android)

Android: draw LatLngBounds on a GoogleMap object

Quick question: If you have a LatLngBounds variable how to transform it to a polygon and draw it on a Google Map view in your Android Application?

LatLngBounds store a rectangle by storing only 2 points from the rectangle the North East and South West, to build a new polygon you need the rest of the points.


public void onMapReady(GoogleMap googleMap) {
   // get the bounds, for this example I will get the visible region on the google map view
   LatLngBounds b = mapObj.getProjection().getVisibleRegion().latLngBounds;

   PolygonOptions po = new PolygonOptions();

   LatLng northwest = new LatLng(b.southwest.latitude, b.northeast.longitude);
   LatLng southeast = new LatLng(b.northeast.latitude, b.southwest.longitude);

   po.add(b.northeast, northwest);
   po.add(northwest, b.southwest);
   po.add(b.southwest, southeast);
   po.add(southeast, b.northeast);



Android issue: INSTALL_FAILED_UID_CHANGED fixed without root or device factory reset

If you are here you probably had the issue from the title the error INSTALL_FAILED_UID_CHANGED when you want to install for debug the app from Eclipse or Android Studio.

I had this issue yesterday and after hours of browsing the stackoverflow and groups and forums I found 3 methods to fix this.

1. if you test on an emulator then you just have to Clear/Wipe the AVD to defaults or create a new one.

2. you are on a real device. If you have root access to the device just go to folder


and delete it. You should ok now.

3. Device with no ROOT Access. On internet there is just one single method to factory reset the device. If this is acceptable for you this is easy.

None of this methods was OK for me. I was testing on a real device with NO-ROOT but I did not want to factory reset it. Continue Reading

How to write & (ampersand) character in Android string resource

Because ampersand or & character break the xml validation in Android string.xml file if you need to insert a text with ampersand you have to encode it like in HTML encode.


<string name="mystring">This is my test & example</string> <!-- this is not ok -->

correct wayWatch movie online Get Out (2017)Watch movie online The Lego Batman Movie (2017)

<string name="mystring">This is my test &amp; example</string> <!-- this is not ok -->

Android get versionCode and versionName from your AndroidManifest.xml

Sometimes showing version in your app is a good think, and when you do this a good think is to not have 2 ore more places where wou have to maintain tha app version for every releases.

In your AndroidManifest.xml there is required 2 fields

android:versionCode witch is an int with the app version

android:versionName witch is a string something like 1.0.1 showing app version.

It is recomanded to use them and do not maintain a separate constant for using it in your code. Ok so programmatically you can retrieve this fields from your AndroidManifest.xml like this:

/* Get android:versionName */
String versionName = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;

/* Get android:versionCode */
int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;