Java Code Examples for android.content.pm.ApplicationInfo#FLAG_EXTERNAL_STORAGE

The following examples show how to use android.content.pm.ApplicationInfo#FLAG_EXTERNAL_STORAGE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppListSorter.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
public AppInfo(final PackageManager packageManager, final PackageInfo p) {
	final ApplicationInfo ai = p.applicationInfo;

	this.path = ai.sourceDir;
	this.label = ai.loadLabel(packageManager).toString();
	this.packageName = p.packageName;
	this.version = p.versionName + "";

	this.isSystemApp = (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
	this.isUpdatedSystemApp = (ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0;
	this.isInternal = (ai.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == 0;
	this.isExternalAsec = (ai.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;

	final File f = new File(path);
	this.longSize = f.length();
	this.size = Util.nf.format(longSize) + " B";
	this.longDate = f.lastModified();
	this.date = Util.dtf.format(longDate);
}
 
Example 2
Source File: AppInstalledActivity.java    From LeanbackTvSample with MIT License 5 votes vote down vote up
public List<AppInfo> getInstallApps(Context context) {
        Log.e(TAG, "getInstallApps0: ");
        PackageManager pm = context.getPackageManager();
        List<PackageInfo> installedPackages = pm.getInstalledPackages(0);  //获取所以已安装的包

        List<AppInfo> list = new ArrayList<>();
        for (PackageInfo packageInfo : installedPackages) {
            Intent intent = pm.getLaunchIntentForPackage(packageInfo.packageName);
            if (intent == null) {
                continue;
            }
            AppInfo info = new AppInfo();
            ApplicationInfo applicationInfo = packageInfo.applicationInfo;  //应用信息
            info.name = applicationInfo.loadLabel(pm).toString();
            info.icon = applicationInfo.loadIcon(pm);        //状态机,通过01状态来表示是否具备某些属性和功能

            info.packageName = packageInfo.packageName;
            info.versionName = packageInfo.versionName;
            info.versionCode = packageInfo.versionCode;
            int flags = applicationInfo.flags;  //获取应用标记
            info.isRom = (flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != ApplicationInfo
                    .FLAG_EXTERNAL_STORAGE;
            info.isUser = (flags & ApplicationInfo.FLAG_SYSTEM) != ApplicationInfo
                    .FLAG_SYSTEM;
//            Log.e(TAG, "getInstallApps: " + info.toString());
            list.add(info);
        }
        Log.e(TAG, "getInstallApps1: ");
        return list;
    }
 
Example 3
Source File: PackageManagerHelper.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns true if the app can possibly be on the SDCard. This is just a workaround and doesn't
 * guarantee that the app is on SD card.
 */
public boolean isAppOnSdcard(String packageName, UserHandle user) {
    ApplicationInfo info = mLauncherApps.getApplicationInfo(

            packageName, uninstalled, user);
    return info != null && (info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
}
 
Example 4
Source File: InstallLocationHelper.java    From offline-calendar with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if the application is installed on the SD card. See
 * http://stackoverflow.com/questions/
 * 5814474/how-can-i-find-out-if-my-app-is-installed-on-sd-card
 *
 * @return true if the application is installed on the sd cards
 */
@SuppressLint("SdCardPath")
public static boolean isInstalledOnSdCard(Context context) {
    PackageManager pm = context.getPackageManager();
    try {
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        ApplicationInfo ai = pi.applicationInfo;
        return (ai.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo.FLAG_EXTERNAL_STORAGE;
    } catch (PackageManager.NameNotFoundException e) {
        // ignore
    }

    return false;
}
 
Example 5
Source File: SettingBase.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
void setFlags(int pkgFlags) {
    this.pkgFlags = pkgFlags
            & (ApplicationInfo.FLAG_SYSTEM
                    | ApplicationInfo.FLAG_EXTERNAL_STORAGE);
}
 
Example 6
Source File: ModuleUtil.java    From EdXposedManager with GNU General Public License v3.0 4 votes vote down vote up
public boolean isInstalledOnExternalStorage() {
    return (app.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
}
 
Example 7
Source File: AppManagerEngine.java    From MobileGuard with MIT License 4 votes vote down vote up
/**
 * get all installed app info
 * Attention: the app size is asynchronous.
 * so you can set a app info listener.
 * you can also set null for listener If you don't use the size info or don't care it.
 * @param context
 * @param listener will be call when app info get completed if not null. The timeout is 3s. It will be call whether success or not.
 * @return a AppInfoBean list. It would never be null.
 */
public static List<AppInfoBean> getInstalledAppInfo(Context context, final AppInfoListener listener) {
    // get manager
    PackageManager pm = context.getPackageManager();
    // get all installed app info
    final List<ApplicationInfo> infos = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    // use for counting the progress of getting size
    class CompletedCountBean {
        int completedCount;
    }
    final CompletedCountBean count = new CompletedCountBean();

    // Create bean list. Here input the certain init count for list
    final List<AppInfoBean> appInfos = new ArrayList<>(infos.size());

    // start a timer to manager the max wait time
    final Timer timer = new Timer(true);
    // if have listener, start it
    if (null != listener) {
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                synchronized (count) {
                    // change the cout first
                    // prevent the if(count.completedCount == infos.size())
                    count.completedCount = -1;
                    listener.onGetInfoCompleted(appInfos);
                }
            }
        };
        timer.schedule(timerTask, 3000);
    }


    for (ApplicationInfo info : infos) {
        // new a AppInfoBean and add to list
        final AppInfoBean bean = new AppInfoBean();
        appInfos.add(bean);

        // set value to bean
        bean.setIcon(info.loadIcon(pm));
        bean.setName(info.loadLabel(pm).toString());
        bean.setPackageName(info.packageName);

        // according to flag to check system and sd card app
        if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            // if have system flag, it is a system app, the value should be true
            bean.setSystemApp(true);
        }// if not have, it should be false. Actually it is.

        if ((info.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
            // if have EXTERNAL_STORAGE flag, it is a sd card app, the value should be true
            bean.setSystemApp(true);
        }// if not have, it should be false. Actually it is.

        // get apk path
        bean.setApkPath(info.sourceDir);
        // get app size
        getAppSize(context, info.packageName, new AppSizeInfoListener() {
            @Override
            public void onGetSizeInfoCompleted(AppSizeInfo sizeInfo) {
                // set size
                long totalSize = sizeInfo.cacheSize + sizeInfo.codeSize + sizeInfo.dataSize;
                bean.setSize(totalSize);
                bean.setCacheSize(sizeInfo.cacheSize);
                // if listener is null, no need to call this
                if(null == listener)
                    return;
                synchronized (count) {
                    count.completedCount++;
                    // if the all app size are got, call the listener
                    if(count.completedCount == infos.size()) {
                        // stop the timer first
                        timer.cancel();
                        listener.onGetInfoCompleted(appInfos);
                    }
                }
            }
        });
    }
    return appInfos;
}