Example usage for android.content.pm PackageManager getPackageInfo

List of usage examples for android.content.pm PackageManager getPackageInfo

Introduction

In this page you can find the example usage for android.content.pm PackageManager getPackageInfo.

Prototype

public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags)
        throws NameNotFoundException;

Source Link

Document

Retrieve overall information about an application package that is installed on the system.

Usage

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

public void DoInfo() {
    try {//from  w w  w .  ja va  2 s  .  c  o  m
        /* First, get the Display from the WindowManager */
        Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
        /* Now we can retrieve all display-related infos */
        Point size = new Point();
        display.getSize(size);
        PackageManager manager = this.getPackageManager();
        PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
        makeToast("PackageName = " + info.packageName + "\nVersionName = " + info.versionName
                + "\nAndroid version " + Build.VERSION.RELEASE + "\nScreen size = " + size.x + "x" + size.y
                + "\nDevelopment: (2013-2016)" + "\n  Android  - P. van der Wielen (Ezac)"
                + "\n  Web Site - E. Fekkes (Ezac)", 0);
        Log.d(TAG, "Name " + info.versionName + ", Code " + info.versionCode);
    } catch (NameNotFoundException pkg) {
        Log.d(TAG, "unable to get app version info !" + pkg.getMessage());
    } finally {
        ;
    }
}

From source file:com.dwdesign.tweetings.util.Utils.java

public static void setUserAgent(final Context context, final ConfigurationBuilder cb) {
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final boolean gzip_compressing = prefs.getBoolean(PREFERENCE_KEY_GZIP_COMPRESSING, true);
    final PackageManager pm = context.getPackageManager();
    try {//  ww  w. j av a2s  .com
        final PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        final String version_name = pi.versionName;
        cb.setClientVersion(pi.versionName);
        //cb.setClientName(APP_NAME);
        cb.setClientURL(APP_PROJECT_URL);
        //cb.setUserAgent(APP_NAME + " " + APP_PROJECT_URL + " / " + version_name
        //      + (gzip_compressing ? " (gzip)" : ""));
    } catch (final PackageManager.NameNotFoundException e) {

    }
}

From source file:me.piebridge.bible.Bible.java

private void checkApkData() {
    Log.d(TAG, "checking apkdata");
    try {//from  ww  w.  java2 s  .c  o  m
        String packageName = mContext.getPackageName();
        PackageManager pm = mContext.getPackageManager();
        SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(mContext);
        ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
        for (String applicationName : pm.getPackagesForUid(ai.uid)) {
            if (packageName.equals(applicationName)) {
                continue;
            }

            // version
            String version = applicationName.replace(packageName + ".", "");

            // resources
            Resources resources = mContext
                    .createPackageContext(applicationName, Context.CONTEXT_IGNORE_SECURITY).getResources();

            // newVersion
            int versionCode = pm.getPackageInfo(applicationName, 0).versionCode;
            boolean newVersion = (preference.getInt(version, 0) != versionCode);

            // resid
            int resid = resources.getIdentifier("a", "raw", applicationName);
            if (resid == 0) {
                resid = resources.getIdentifier("xa", "raw", applicationName);
            }
            if (resid == 0) {
                Log.d(TAG, "package " + applicationName + " has no R.raw.a nor R.raw.xa");
                continue;
            }

            // file
            File file;
            if (versionpaths.containsKey(version)) {
                file = new File(versionpaths.get(version));
            } else {
                file = new File(getExternalFilesDirWrapper(), version + ".sqlite3");
            }
            if (file.exists() && !file.isFile()) {
                file.delete();
            }

            boolean unpack = unpackRaw(resources, newVersion, resid, file);
            if (newVersion && unpack) {
                preference.edit().putInt(version, versionCode).commit();
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "", e);
    }
}

From source file:com.androzic.Androzic.java

public void onCreateEx() {
    try {//from  w  w w  .  jav a  2s .  c o  m
        (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER)).mkdirs();
        (new File(Environment.getExternalStorageDirectory(), WordManager.FOLDER + "/ghiam")).mkdirs();
    } catch (Throwable e) {
    }

    if (initialized)
        return;

    AndroidGraphicFactory.createInstance(this);
    try {
        OzfDecoder.useNativeCalls();
    } catch (UnsatisfiedLinkError e) {
        Toast.makeText(Androzic.this, "Failed to initialize native library: " + e.getMessage(),
                Toast.LENGTH_LONG).show();
    }

    Resources resources = getResources();
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    Configuration config = resources.getConfiguration();

    renderingThread = new HandlerThread("RenderingThread");
    renderingThread.start();

    longOperationsThread = new HandlerThread("LongOperationsThread");
    longOperationsThread.setPriority(Thread.MIN_PRIORITY);
    longOperationsThread.start();

    uiHandler = new Handler();
    mapsHandler = new Handler(longOperationsThread.getLooper());

    // We silently initialize data uri to let location service restart after crash
    File datadir = new File(
            settings.getString(getString(R.string.pref_folder_data), Environment.getExternalStorageDirectory()
                    + File.separator + resources.getString(R.string.def_folder_data)));
    setDataPath(Androzic.PATH_DATA, datadir.getAbsolutePath());

    setInstance(this);

    String intentToCheck = "com.androzic.donate";
    String myPackageName = getPackageName();
    PackageManager pm = getPackageManager();
    PackageInfo pi;
    try {
        pi = pm.getPackageInfo(intentToCheck, 0);
        isPaid = (pm.checkSignatures(myPackageName, pi.packageName) == PackageManager.SIGNATURE_MATCH);
    } catch (NameNotFoundException e) {
        //         e.printStackTrace();
    }

    File sdcard = Environment.getExternalStorageDirectory();
    Thread.setDefaultUncaughtExceptionHandler(new CrashHandler(this, sdcard.getAbsolutePath()));

    DisplayMetrics displayMetrics = new DisplayMetrics();

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    if (wm != null) {
        wm.getDefaultDisplay().getMetrics(displayMetrics);
    } else {
        displayMetrics.setTo(resources.getDisplayMetrics());
    }
    BaseMap.viewportWidth = displayMetrics.widthPixels;
    BaseMap.viewportHeight = displayMetrics.heightPixels;

    charset = settings.getString(getString(R.string.pref_charset), "UTF-8");
    String lang = settings.getString(getString(R.string.pref_locale), "");
    if (!"".equals(lang) && !config.locale.getLanguage().equals(lang)) {
        locale = new Locale(lang);
        Locale.setDefault(locale);
        config.locale = locale;
        resources.updateConfiguration(config, resources.getDisplayMetrics());
    }

    magInterval = resources.getInteger(R.integer.def_maginterval) * 1000;

    overlayManager = new OverlayManager(longOperationsThread.getLooper());
    TooltipManager.initialize(this);

    onSharedPreferenceChanged(settings, getString(R.string.pref_unitcoordinate));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitdistance));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitspeed));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitelevation));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitangle));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitanglemagnetic));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitprecision));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitsunrise));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapadjacent));
    onSharedPreferenceChanged(settings, getString(R.string.pref_vectormap_textscale));
    onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapprescalefactor));
    onSharedPreferenceChanged(settings, getString(R.string.pref_onlinemapexpiration));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapcropborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapdrawborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showwaypoints));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showcurrenttrack));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showaccuracy));
    onSharedPreferenceChanged(settings, getString(R.string.pref_showdistance_int));

    settings.registerOnSharedPreferenceChangeListener(this);

    initialized = true;
}

From source file:com.amaze.filemanager.activities.MainActivity.java

void initialiseFab() {
    String folder_skin = PreferenceUtils.getFolderColorString(Sp);
    int fabSkinPressed = PreferenceUtils.getStatusColor(fabskin);
    int folderskin = Color.parseColor(folder_skin);
    int fabskinpressed = (PreferenceUtils.getStatusColor(folder_skin));
    floatingActionButton = (FloatingActionMenu) findViewById(R.id.menu);
    floatingActionButton.setMenuButtonColorNormal(Color.parseColor(fabskin));
    floatingActionButton.setMenuButtonColorPressed(fabSkinPressed);

    //if (theme1 == 1) floatingActionButton.setMen
    floatingActionButton.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() {
        @Override// w  w w  .  ja v  a 2 s.c  om
        public void onMenuToggle(boolean b) {
            View v = findViewById(R.id.fab_bg);
            if (b)
                revealShow(v, true);
            else
                revealShow(v, false);
        }
    });

    FloatingActionButton floatingActionButton1 = (FloatingActionButton) findViewById(R.id.menu_item);
    floatingActionButton1.setColorNormal(folderskin);
    floatingActionButton1.setColorPressed(fabskinpressed);
    floatingActionButton1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mainActivityHelper.add(0);
            revealShow(findViewById(R.id.fab_bg), false);
            floatingActionButton.close(true);
        }
    });
    FloatingActionButton floatingActionButton2 = (FloatingActionButton) findViewById(R.id.menu_item1);
    floatingActionButton2.setColorNormal(folderskin);
    floatingActionButton2.setColorPressed(fabskinpressed);
    floatingActionButton2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mainActivityHelper.add(1);
            revealShow(findViewById(R.id.fab_bg), false);
            floatingActionButton.close(true);
        }
    });
    FloatingActionButton floatingActionButton3 = (FloatingActionButton) findViewById(R.id.menu_item2);
    floatingActionButton3.setColorNormal(folderskin);
    floatingActionButton3.setColorPressed(fabskinpressed);
    floatingActionButton3.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mainActivityHelper.add(2);
            revealShow(findViewById(R.id.fab_bg), false);
            floatingActionButton.close(true);
        }
    });
    final FloatingActionButton floatingActionButton4 = (FloatingActionButton) findViewById(R.id.menu_item3);
    floatingActionButton4.setColorNormal(folderskin);
    floatingActionButton4.setColorPressed(fabskinpressed);
    floatingActionButton4.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mainActivityHelper.add(3);
            revealShow(findViewById(R.id.fab_bg), false);
            floatingActionButton.close(true);
        }
    });

    new Thread(new Runnable() {
        @Override
        public void run() {
            PackageManager pm = getPackageManager();
            boolean app_installed;
            try {
                pm.getPackageInfo("com.amaze.filemanager.driveplugin", PackageManager.GET_ACTIVITIES);
                app_installed = true;
            } catch (PackageManager.NameNotFoundException e) {
                app_installed = false;
            }
            if (!app_installed)
                floatingActionButton4.setVisibility(View.GONE);
        }
    }).run();
}

From source file:cm.aptoide.pt.MainActivity.java

private boolean isAppInstalled(String uri) {
    PackageManager pm = getPackageManager();
    boolean installed = false;
    try {/*  w ww.  ja va  2 s  .co m*/
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        installed = false;
    }
    return installed;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void setUserAgent(final Context context, final ConfigurationBuilder cb) {
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final boolean gzip_compressing = prefs.getBoolean(KEY_GZIP_COMPRESSING, true);
    final PackageManager pm = context.getPackageManager();
    try {//  w  ww  .  j a  va 2s .  c om
        final PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        final String version_name = pi.versionName;
        cb.setClientVersion(pi.versionName);
        cb.setClientName(APP_NAME);
        cb.setClientURL(APP_PROJECT_URL);
        cb.setHttpUserAgent(
                APP_NAME + " " + APP_PROJECT_URL + " / " + version_name + (gzip_compressing ? " (gzip)" : ""));
    } catch (final PackageManager.NameNotFoundException e) {

    }
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void setUserAgent(final Context context, final ConfigurationBuilder cb) {
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final boolean gzipCompressing = prefs.getBoolean(KEY_GZIP_COMPRESSING, true);
    final PackageManager pm = context.getPackageManager();
    try {/*from w  w w  .j ava 2  s .  c o m*/
        final PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        final String version_name = pi.versionName;
        cb.setClientVersion(pi.versionName);
        cb.setClientName(APP_NAME);
        cb.setClientURL(APP_PROJECT_URL);
        cb.setHttpUserAgent(
                APP_NAME + " " + APP_PROJECT_URL + " / " + version_name + (gzipCompressing ? " (gzip)" : ""));
    } catch (final PackageManager.NameNotFoundException e) {
        Crashlytics.logException(e);
        throw new AssertionError(e);
    }
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String StrtUpdtOMatic(String sPkgName, String sPkgFileName, String sCallBackIP, String sCallBackPort) {
    String sRet = "";

    Context ctx = contextWrapper.getApplicationContext();
    PackageManager pm = ctx.getPackageManager();

    Intent prgIntent = new Intent();
    prgIntent.setPackage("com.mozilla.watcher");

    try {//from  ww  w  . j  a  v  a 2  s  .c o m
        PackageInfo pi = pm.getPackageInfo("com.mozilla.watcher",
                PackageManager.GET_SERVICES | PackageManager.GET_INTENT_FILTERS);
        ServiceInfo[] si = pi.services;
        for (int i = 0; i < si.length; i++) {
            ServiceInfo s = si[i];
            if (s.name.length() > 0) {
                prgIntent.setClassName(s.packageName, s.name);
                break;
            }
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        sRet = sErrorPrefix + "watcher is not properly installed";
        return (sRet);
    }

    prgIntent.putExtra("command", "updt");
    prgIntent.putExtra("pkgName", sPkgName);
    prgIntent.putExtra("pkgFile", sPkgFileName);
    prgIntent.putExtra("reboot", true);

    try {
        if ((sCallBackIP != null) && (sCallBackPort != null) && (sCallBackIP.length() > 0)
                && (sCallBackPort.length() > 0)) {
            FileOutputStream fos = ctx.openFileOutput("update.info",
                    Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
            String sBuffer = sCallBackIP + "," + sCallBackPort + "\rupdate started " + sPkgName + " "
                    + sPkgFileName + "\r";
            fos.write(sBuffer.getBytes());
            fos.flush();
            fos.close();
            fos = null;
            prgIntent.putExtra("outFile", ctx.getFilesDir() + "/update.info");
        } else {
            if (prgIntent.hasExtra("outFile")) {
                System.out.println("outFile extra unset from intent");
                prgIntent.removeExtra("outFile");
            }
        }

        ComponentName cn = contextWrapper.startService(prgIntent);
        if (cn != null)
            sRet = "exit";
        else
            sRet = sErrorPrefix + "Unable to use watcher service";
    } catch (ActivityNotFoundException anf) {
        sRet = sErrorPrefix + "Activity Not Found Exception [updt] call failed";
        anf.printStackTrace();
    } catch (FileNotFoundException e) {
        sRet = sErrorPrefix + "File creation error [updt] call failed";
        e.printStackTrace();
    } catch (IOException e) {
        sRet = sErrorPrefix + "File error [updt] call failed";
        e.printStackTrace();
    }

    ctx = null;

    return (sRet);
}