Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.lang.reflect.Field;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;

public class Main {
    public static final int MOVEAPPTYPE_MOVETOSDCARD = 1;
    public static final int MOVEAPPTYPE_MOVETOPHONE = 2;
    public static final int MOVEAPPTYPE_NONE = 3;
    public static final int FLAG_EXTERNAL_STORAGE = 1 << 18;

    public static int getMoveType(PackageInfo pInfo, ApplicationInfo info) {
        int moveType = MOVEAPPTYPE_NONE;
        if ((FLAG_EXTERNAL_STORAGE & info.flags) != 0) {
            moveType = MOVEAPPTYPE_MOVETOPHONE;
        } else if (pInfo != null) {
            int installLocation = 1;
            try {
                Field field = pInfo.getClass().getDeclaredField("installLocation");
                field.setAccessible(true);
                installLocation = field.getInt(pInfo);
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            if (installLocation == 0) {
                moveType = MOVEAPPTYPE_MOVETOSDCARD;
            } else if (installLocation == -1 || installLocation == 1) {
                moveType = MOVEAPPTYPE_NONE;
            }
        }
        return moveType;
    }
}