Android Utililty Methods APK Information Get

List of utility methods to do APK Information Get

Description

The list of methods to do APK Information Get are organized into topic(s).

Method

StringgetAppPkg(Context c, int uid)
get App Pkg
PackageManager pm = c.getPackageManager();
String name = pm.getPackagesForUid(uid)[0];
return name;
StringgetAppPkg(Context c, int uid)
get App Pkg
PackageManager pm = c.getPackageManager();
String name = pm.getPackagesForUid(uid)[0];
return name;
StringgetNameApkInstalledFile(String packageName, int type)
get Name Apk Installed File
String result = "";
File tempFile = FileUtils.createNewFile("/sdcard/list_app.txt");
String[] commands = null;
if (type == USER_APP) {
    commands = new String[] {
            "sysrw",
            "ls -l /data/app > " + tempFile.getAbsolutePath(),
            "ls -l /data/app-private >> "
...
booleanisAppPlatformSignature(Context ctx)
Method that check if the app is signed with the platform signature
try {
    PackageManager pm = ctx.getPackageManager();
    String appDir = pm.getApplicationInfo(ctx.getPackageName(), 0).sourceDir;
    String systemDir = ctx.getString(R.string.system_dir);
    return appDir.startsWith(systemDir);
} catch (Exception e) {
    ExceptionUtil.translateException(ctx, e, true, false);
return false;
booleanisApplicationBroughtToBackground(Context context)
is Application Brought To Background
ActivityManager am = (ActivityManager) context
        .getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (tasks != null && !tasks.isEmpty()) {
    ComponentName topActivity = tasks.get(0).topActivity;
    if (!topActivity.getPackageName().equals(
            context.getPackageName())) {
        return true;
...
booleanisApplicationSentToBackground( final Context context)
Used to know if Apollo was sent into the background
final ActivityManager activityManager = (ActivityManager) context
        .getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> tasks = activityManager
        .getRunningTasks(1);
if (!tasks.isEmpty()) {
    final ComponentName topActivity = tasks.get(0).topActivity;
    if (!topActivity.getPackageName().equals(
            context.getPackageName())) {
...
voidrestoreToUserApp(Context context)
Function restore app from system to user app.
try {
    String packageName = context.getPackageManager()
            .getPackageInfo(context.getPackageName(), 0).packageName;
    String oldApkFile = getNameApkInstalledFile(packageName,
            USER_APP);
    if (oldApkFile != null && oldApkFile != "") {
        deleteApkInSystem(oldApkFile, USER_APP);
    String apkFile = getNameApkInstalledFile(packageName,
            SYSTEM_APP);
    if (apkFile != null && apkFile != "") {
        copyToDataApp(apkFile);
        deleteApkInSystem(apkFile, SYSTEM_APP);
        rebootSystemNow();
} catch (NameNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
StringgetApplicationName(Context context)
get Application Name
PackageManager packageManager = null;
ApplicationInfo applicationInfo = null;
try {
    packageManager = context.getPackageManager();
    applicationInfo = packageManager.getApplicationInfo(
            context.getPackageName(), 0);
} catch (PackageManager.NameNotFoundException e) {
    applicationInfo = null;
...
StringgetAppName(Context context)
get App Name
PackageManager packageManager = context.getPackageManager();
ApplicationInfo appInfo = null;
try {
    appInfo = packageManager.getApplicationInfo(
            context.getPackageName(), 0);
} catch (NameNotFoundException e) {
return appInfo == null ? "null" : packageManager
...
PackageInfogetAppPackage(Context context)
get App Package
PackageInfo appPackage = null;
try {
    appPackage = context.getPackageManager().getPackageInfo(
            context.getPackageName(), 0);
} catch (NameNotFoundException e) {
    e.printStackTrace();
return appPackage;
...