Sunday 27 March 2016

How to create android app with movable to sd card feature?


It is very simple to enable move to SD card feature in Android applications, all you need to do is specify the installLocation attribute in Android manifest as ‘auto’.


1
2
3
4
5
6
7
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.prgguru.sdmovable"
    android:versionCode="1"
    android:versionName="1.0" android:installLocation="auto">
...
</manifest>

installLocation attribute can be assigned with following values:

auto
It indicates that your application may be installed on the internal memory (or) external storage, but you don’t have a preference of install location. The system will decide where to install your application based on several factors. The user can also move your application between the two locations.
internalOnly
If you’re certain that your application should never be installed on the external storage, assign installLocation attribute value as ‘internalOnly’.
preferExternal
You request that your application be installed on the external storage, but the system does not guarantee that your application will be installed on the external storage. If the external storage is full, the system will install it on the internal storage. The user can also move your application between the two locations.

Saturday 12 March 2016

RoundedShape ImageView


In a modern android application, user or profile pictures are shown in a rounded shape and those images filled out with the aspect ratio.

Use the below code to achieve that.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
        int targetWidth = 50;
        int targetHeight = 50;
        Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
                targetHeight,Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(targetBitmap);
        Path path = new Path();
        path.addCircle(((float) targetWidth - 1) / 2,
                ((float) targetHeight - 1) / 2,
                (Math.min(((float) targetWidth),
                        ((float) targetHeight)) / 2),
                Path.Direction.CCW);

        canvas.clipPath(path);
        Bitmap sourceBitmap = scaleBitmapImage;
        canvas.drawBitmap(sourceBitmap,
                new Rect(0, 0, sourceBitmap.getWidth(),
                        sourceBitmap.getHeight()),
                new Rect(0, 0, targetWidth, targetHeight), null);
        return targetBitmap;
    }

Please refer the link for the Bitmap Image Scaling as to the aspect ratio here,

Done!