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.rei.lolchat.ui.Login.java

/**
 * Create an about "BEEM" dialog.//w w  w  . j  a va2 s  .  c o m
 */
private void createAboutDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String versionname;
    try {
        PackageManager pm = getPackageManager();
        PackageInfo pi = pm.getPackageInfo("com.rei.lolchat", 0);
        versionname = pi.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        versionname = "";
    }
    String title = getString(R.string.login_about_title, versionname);
    builder.setTitle(title).setMessage(R.string.login_about_msg).setCancelable(false);
    builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });
    AlertDialog aboutDialog = builder.create();
    aboutDialog.show();
}

From source file:net.healeys.lexic.online.OnlineGame.java

public OnlineGame(Context c, String uri) throws Exception {
    super(c);/*w  w w. j  a va  2s.com*/

    this.uri = uri;

    // Set up userAgent
    PackageManager pm = c.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(c.getPackageName(), 0);
    userAgent = "Lexic (" + pi.packageName + " " + pi.versionName + " " + pi.versionCode + ")";

    // Set up session id
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    String loginId = prefs.getString("login_id", null);
    sessionid = "sessionid=" + loginId;

    urls = new HashMap<String, String>();
}

From source file:net.healeys.lexic.online.OnlineGame.java

public OnlineGame(Context c, Bundle bun) throws Exception {
    super(c, bun, true);

    uri = bun.getString("uri");

    // Set up userAgent
    PackageManager pm = c.getPackageManager();
    PackageInfo pi = pm.getPackageInfo(c.getPackageName(), 0);
    userAgent = "Lexic (" + pi.packageName + " " + pi.versionName + " " + pi.versionCode + ")";

    // Set up session id
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(c);
    String loginId = prefs.getString("login_id", null);
    sessionid = "sessionid=" + loginId;

    urls = new HashMap<String, String>();
    urls.put("words", bun.getString("words_url"));
    urls.put("score", bun.getString("score_url"));

}

From source file:cn.ttyhuo.common.MyApplication.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressWarnings("unused")
@Override/*  w w  w . j a v  a 2s  .  com*/
public void onCreate() {
    super.onCreate();

    context = getApplicationContext();
    cookieStore = new PersistentCookieStore(context);

    initImageLoader(getApplicationContext());

    mLocationClient = new LocationClient(getApplicationContext());
    mMyLocationListener = new MyLocationListener();
    mLocationClient.registerLocationListener(mMyLocationListener);
    InitLocation();
    mLocationClient.start();

    try {
        PackageManager manager = this.getPackageManager();
        info = manager.getPackageInfo(this.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }

    SDKInitializer.initialize(getApplicationContext());
}

From source file:com.example.helloworldlinked.backend.HelloWorldService.java

private boolean isProviderInstalled() {
    PackageManager pm = getPackageManager();

    try {/*from   w ww.  ja va 2  s.  c  om*/
        pm.getPackageInfo(HELLO_WORLD_PROVIDER_PACKAGE_NAME, PackageManager.GET_SERVICES);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:com.android.applications.todoist.views.SupportForm.java

private void rpcCall() {
    if (checkValues()) {
        Context context = getApplicationContext();
        PackageInfo info;//ww  w. j  ava  2  s  . co  m

        try {
            // read current version information about this package
            PackageManager manager = context.getPackageManager();
            info = manager.getPackageInfo(context.getPackageName(), 0);

        } catch (Exception e) {
            //TODO: Something better here :-D
            Log.e("SupportCase", "Couldn't find package information in PackageManager", e);
            return;
        }

        // Create a SupportCase w/ the information entered
        SupportCase newCase = new SupportCase(this.nameText.getText().toString(),
                this.emailText.getText().toString(), this.problemText.getText().toString(), "",
                this.areaSpinner.getSelectedItem().toString(), info.packageName, info.versionName);

        // Report the problem
        // TODO: Add something to XMLRPCMethod that checks the result of the page (in case the site is down) 
        XMLRPCMethod method = new XMLRPCMethod("reportproblem", new XMLRPCMethodCallback() {
            public void callFinished(Object result, String str) {
                if ((Boolean) result && emailText.getText().length() != 0) {
                    showAlert("Success!",
                            "The problem was reported successfully. \n\nYou should receive an automated e-mail in the next few hours.",
                            "OK", true);
                } else if ((Boolean) result) {
                    showAlert("Success!",
                            "The problem was reported successfully. \n\nNotice: Since you did not enter your e-mail address, there will be no correspondance.",
                            "OK", true);
                } else {
                    showAlert("Failure!",
                            "The problem failed to be reported.  Please try again shortly.  If this problem persists, please contact Admin@DrewDahl.com.",
                            "OK", false);
                }
            }
        });

        Object[] params = { newCase, };

        method.call(params);
    }
}

From source file:pam.widget.activities.EntityBoardActivity.java

private EntityBoard getEntityBoardFromApi(Bundle extras) {
    HttpClient httpclient = new DefaultHttpClient();

    String myVersion = "0.0";
    PackageManager manager = getBaseContext().getPackageManager();
    try {/*from  w  ww.  j av a 2s  . c o  m*/
        myVersion = (manager.getPackageInfo(getBaseContext().getPackageName(), 0).versionName);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    httpclient.getParams().setParameter("http.useragent",
            "PamelaWidget " + myVersion + " for Android - " + System.getProperty("http.agent"));

    String url = extras.getString("URL") + "?lang=" + getString(R.string.lang);
    // Prepare a request object
    HttpGet httpget = new HttpGet(url.replace(" ", "%20"));
    Log.i("", url);

    // Execute the request
    HttpResponse response;

    JSONArray json = new JSONArray();

    Date currentDate = new Date();
    String space = extras.getString("Name");
    ArrayList<Entity> entities = new ArrayList<Entity>();

    try {
        response = httpclient.execute(httpget);

        HttpEntity httpEntity = response.getEntity();

        if (httpEntity != null) {

            // A Simple JSON Response Read
            InputStream instream = httpEntity.getContent();
            String result = convertStreamToString(instream);

            json = new JSONArray(result);

            instream.close();
        }

        for (int i = 0; i < json.length(); ++i) {
            String rawName = json.getString(i);
            String displayName = rawName;
            Type type = Type.UNKNOWN;
            String customType = "";

            if (rawName.split(":").length != 6) {

                if (rawName.indexOf("(") != -1 && rawName.indexOf(")") > rawName.indexOf("(")) {
                    type = Type.DEVICE;
                    customType = rawName.substring(rawName.indexOf("(") + 1, rawName.indexOf(")"));
                    customType = customType.substring(0, 1).toUpperCase() + customType.substring(1);
                    displayName = rawName.substring(0, rawName.indexOf("("));
                } else {
                    type = Type.PERSON;
                }
            }

            Entity entity = new Entity(displayName, type, Status.ACTIVE);

            if (customType != "") {
                entity.setCustomType(customType);
            }

            entities.add(entity);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    ArrayList<Entity> orderedEntities = new ArrayList<Entity>();

    int peopleAmount = this.addEntitiesOfType(entities, orderedEntities, Type.PERSON);
    this.addEntitiesOfType(entities, orderedEntities, Type.DEVICE);
    int unknownAmount = this.addEntitiesOfType(entities, orderedEntities, Type.UNKNOWN);

    Boolean spaceIsOpen = peopleAmount > 0 || unknownAmount > 0;
    space = space + " (" + getString(spaceIsOpen ? R.string.open : R.string.closed) + ")";

    return new EntityBoard(currentDate, space, orderedEntities);
}

From source file:com.afwsamples.testdpc.provision.PostProvisioningTask.java

private List<String> getRuntimePermissions(PackageManager packageManager, String packageName) {
    List<String> permissions = new ArrayList<>();
    PackageInfo packageInfo;/* w ww.  j av a  2s  . com*/
    try {
        packageInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not retrieve info about the package: " + packageName, e);
        return permissions;
    }

    if (packageInfo != null && packageInfo.requestedPermissions != null) {
        for (String requestedPerm : packageInfo.requestedPermissions) {
            if (isRuntimePermission(packageManager, requestedPerm)) {
                permissions.add(requestedPerm);
            }
        }
    }
    return permissions;
}

From source file:com.mhise.util.MHISEUtil.java

public static int getVersionCode(Context context) {
    PackageManager pm = context.getPackageManager();
    try {//ww w .  ja va 2s. co  m
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        return pi.versionCode;
    } catch (NameNotFoundException ex) {
    }
    return 0;
}

From source file:com.mhise.util.MHISEUtil.java

public static double getVersionName(Context context) {
    PackageManager pm = context.getPackageManager();
    try {//from   www .  ja  va2 s. co m
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);

        Log.e("dfsdf", pi.versionName + " " + Double.parseDouble(pi.versionName));
        return Double.parseDouble(pi.versionName);
    } catch (NameNotFoundException ex) {
    }
    return 0;
}