Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

public class Main {
    private static Activity mContext;

    public static List<ApplicationInfo> getInstalledApps() {
        if (mContext != null) {
            final PackageManager pm = mContext.getPackageManager();
            return pm.getInstalledApplications(PackageManager.GET_META_DATA);
        } else
            return null;
    }

    public static List<ApplicationInfo> getInstalledApps(boolean onlySupportedApps) {
        if (mContext != null) {
            List<ApplicationInfo> ai = getInstalledApps();
            if (!onlySupportedApps)
                return ai;

            List<ApplicationInfo> res = new ArrayList<ApplicationInfo>();
            for (ApplicationInfo pi : ai) {
                if (isBackupSupportedForApp(pi.packageName)) {
                    res.add(pi);
                }
            }

            return res;
        } else
            return null;
    }

    public static boolean isBackupSupportedForApp(String appPackageName) {
        boolean supported = true;
        if (appPackageName == null)
            return false;
        // UNTESTED APPS BUT PROBABLY BAD IDEA TO RESTORE DATA
        if (appPackageName.startsWith("com.android.") || appPackageName.startsWith("com.google.")
                || appPackageName.startsWith("android"))
            supported = false;
        if (appPackageName.startsWith("com.bel.android.") || appPackageName.startsWith("com.cyanogenmod.")
                || appPackageName.startsWith("com.koushikdutta."))
            supported = false;
        if (appPackageName.startsWith("com.swype.") || appPackageName.startsWith("com.svox.")
                || appPackageName.startsWith("com.tmobile.theme"))
            supported = false;
        // UNTESTED APPS BUT PROBABLY USELESS OR USER UNLIKELY TO RESTORE DATA
        if (appPackageName.startsWith("jackpal.androidterm")
                || appPackageName.startsWith("com.noshufou.android.su"))
            supported = false;
        return supported;
    }
}