List of usage examples for android.content.pm PackageManager getPackageInfo
public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags) throws NameNotFoundException;
From source file:uk.org.openseizuredetector.OsdUtil.java
public String getAppVersionName() { String versionName = "unknown"; // From http://stackoverflow.com/questions/4471025/ // how-can-you-get-the-manifest-version-number- // from-the-apps-layout-xml-variable final PackageManager packageManager = mContext.getPackageManager(); if (packageManager != null) { try {/*www . j a v a 2 s . c o m*/ PackageInfo packageInfo = packageManager.getPackageInfo(mContext.getPackageName(), 0); versionName = packageInfo.versionName; } catch (PackageManager.NameNotFoundException e) { Log.v(TAG, "failed to find versionName"); versionName = null; } } return versionName; }
From source file:de.sitewaerts.cordova.documentviewer.DocumentViewerPlugin.java
private boolean _appIsInstalled(String packageId) { PackageManager pm = cordova.getActivity().getPackageManager(); try {//from ww w . j av a 2s.c om pm.getPackageInfo(packageId, PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:com.android.screenspeak.ScreenSpeakUpdateHelper.java
public void checkUpdate() { final int previousVersion = mSharedPreferences.getInt(PREF_APP_VERSION, -1); final PackageManager pm = mService.getPackageManager(); final int currentVersion; try {/*from www . j a v a 2 s . c om*/ final PackageInfo packageInfo = pm.getPackageInfo(mService.getPackageName(), 0); currentVersion = packageInfo.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); return; } if (previousVersion == currentVersion) { return; } final Editor editor = mSharedPreferences.edit(); editor.putInt(PREF_APP_VERSION, currentVersion); // Handle bug when updating from Revision 68 on Jelly Bean factory ROM if (needsExploreByTouchHelper(previousVersion)) { mService.addEventListener(new ExploreByTouchUpdateHelper(mService)); } // Revision 74 changes the gesture model added in revision 68. if ((previousVersion >= 68) && (previousVersion < 74)) { notifyUserOfGestureChanges(); } // Revision 84 combines the ScreenSpeak and continuous reading breakout // menus. References to the continuous reading menu are silently // remapped to the local breakout menu. if (previousVersion < 84) { remapContinuousReadingMenu(); } // Revision 90 removes the "shake to read" checkbox preference and // replaces it with a list preference of shake velocity thresholds that // includes a default "Off" option. if (previousVersion < 90) { remapShakeToReadPref(); } // Revision 97 moved granularity selection into a local context menu, so // the up-then-down and down-then-up gestures were remapped to help // users navigate past groups of things, like web content and lists. if ((previousVersion != -1) && (previousVersion < 97)) { notifyUserOfBuiltInGestureChanges(); } editor.apply(); }
From source file:info.snowhow.plugin.RecorderService.java
@Override public void onCreate() { Log.d(LOG_TAG, "onCreate called in service"); mgpsll = new MyLocationListener(); mnetll = new MyLocationListener(); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); editor = sharedPref.edit();//from ww w . jav a2s. c o m locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Log.d(LOG_TAG, "locationManager initialized, starting intent"); try { PackageManager packageManager = this.getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(this.getPackageName(), 0); applicationName = packageManager.getApplicationLabel(packageInfo.applicationInfo).toString(); } catch (android.content.pm.PackageManager.NameNotFoundException e) { /* do nothing, fallback is used as name */ } registerReceiver(RecorderServiceBroadcastReceiver, new IntentFilter(ifString)); startGPSS(); }
From source file:it.scoppelletti.mobilepower.app.AboutActivity.java
/** * Costruisce il testo da visualizzare./*from w w w . j av a2s .c o m*/ * * @return Testo. */ private String buildText() { String pkgName, value; StringBuilder buf; Bundle data; ApplicationInfo applInfo; PackageInfo pkgInfo; PackageManager pkgMgr; pkgName = getPackageName(); pkgMgr = getPackageManager(); try { applInfo = pkgMgr.getApplicationInfo(pkgName, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException ex) { myLogger.error("Failed to get ApplicationInfo.", ex); applInfo = getApplicationInfo(); } try { pkgInfo = pkgMgr.getPackageInfo(pkgName, 0); } catch (PackageManager.NameNotFoundException ex) { myLogger.error("Failed to get PackageInfo.", ex); pkgInfo = null; } buf = new StringBuilder(); buf.append("<h1>"); buf.append(pkgMgr.getApplicationLabel(applInfo)); if (pkgInfo != null) { buf.append("<br />"); buf.append(pkgInfo.versionName); } buf.append("</h1>"); data = applInfo.metaData; if (data == null) { return buf.toString(); } value = data.getString(AboutActivity.METADATA_COPYRIGHT); if (!StringUtils.isBlank(value)) { buf.append("<p>"); buf.append(value); buf.append("</p>"); } value = data.getString(AboutActivity.METADATA_LICENSE); if (!StringUtils.isBlank(value)) { buf.append(value); } value = data.getString(AppUtils.METADATA_FULLPACKAGE); if (!StringUtils.isBlank(value)) { buf.append(getString(R.string.msg_demo)); } return buf.toString(); }
From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncPinSongsTask.java
@Override protected Boolean doInBackground(String... params) { //Iterate through the cursor and download/cache the requested songs. boolean getAllPinnedTracks = false; if (mApp.getPinnedSongsCursor() == null) { //The user asked to get all pinned songs from the official GMusic app. getAllPinnedTracks = true;//from w w w .j a v a2 s .c o m //Check to make sure that the official GMusic app exists. PackageManager pm = mContext.getPackageManager(); boolean installed = false; try { pm.getPackageInfo("com.google.android.music", PackageManager.GET_ACTIVITIES); installed = true; } catch (NameNotFoundException e1) { //The app isn't installed. installed = false; } if (installed == false) { //The app isn't installed. Notify the user. publishProgress(new Integer[] { 2 }); return false; } //Query GMusic's content mApp for pinned songs. Uri googlePlayMusicContentProviderUri = Uri .parse("content://com.google.android.music.MusicContent/audio"); String[] projection = { "title", "TrackType AS track_type", "LocalCopyPath AS local_copy_path", "SourceType AS source_type", "SourceId" }; /* source_type values: * 0: Local file (not used). * 1: Unknown. * 2: Personal, free GMusic library (used). * 3: All Access (not used). */ String selection = "source_type=2 AND track_type=0 AND local_copy_path<>''"; mApp.setPinnedSongsCursor(mContext.getContentResolver().query(googlePlayMusicContentProviderUri, projection, selection, null, null)); } /* Load the cursor data into a temp ArrayList. If the app is closed, the cursor * will also be closed, so we need to preserve it. */ mApp.getPinnedSongsCursor().moveToPosition(-1); while (mApp.getPinnedSongsCursor().moveToNext()) { //Download the song only if it's from GMusic. if (getAllPinnedTracks || mApp.getPinnedSongsCursor() .getString(mApp.getPinnedSongsCursor().getColumnIndex(DBAccessHelper.SONG_SOURCE)) .equals(DBAccessHelper.GMUSIC)) { //Retrieve the song ID of current song and set it as the file name. String songID = ""; String songTitle = ""; if (mApp.getPinnedSongsCursor().getColumnIndex("SourceId") != -1) { songID = mApp.getPinnedSongsCursor() .getString(mApp.getPinnedSongsCursor().getColumnIndex("SourceId")); songTitle = mApp.getPinnedSongsCursor() .getString(mApp.getPinnedSongsCursor().getColumnIndex("title")); } else { songID = mApp.getPinnedSongsCursor() .getString(mApp.getPinnedSongsCursor().getColumnIndex(DBAccessHelper.SONG_ID)); songTitle = mApp.getPinnedSongsCursor() .getString(mApp.getPinnedSongsCursor().getColumnIndex(DBAccessHelper.SONG_TITLE)); } songIdsList.add(songID); songTitlesList.add(songTitle); } } //Clear out Common's cursor. if (mApp.getPinnedSongsCursor() != null) { mApp.getPinnedSongsCursor().close(); mApp.setPinnedSongsCursor(null); } //Iterate through the songs and download them. for (i = 0; i < songIdsList.size(); i++) { downloadSong(songIdsList.get(i)); } return true; }
From source file:RhodesService.java
public static void runApplication(String appName, Object params) { try {//from www. j a v a2 s . c o m Context ctx = RhodesService.getContext(); PackageManager mgr = ctx.getPackageManager(); PackageInfo info = mgr.getPackageInfo(appName, PackageManager.GET_ACTIVITIES); if (info.activities.length == 0) { Logger.E(TAG, "No activities found for application " + appName); return; } ActivityInfo ainfo = info.activities[0]; String className = ainfo.name; if (className.startsWith(".")) className = ainfo.packageName + className; Intent intent = new Intent(); intent.setClassName(appName, className); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (params != null) { Bundle startParams = new Bundle(); if (params instanceof String) { if (((String) params).length() != 0) { String[] paramStrings = ((String) params).split("&"); for (int i = 0; i < paramStrings.length; ++i) { String key = paramStrings[i]; String value = ""; int splitIdx = key.indexOf('='); if (splitIdx != -1) { value = key.substring(splitIdx + 1); key = key.substring(0, splitIdx); } startParams.putString(key, value); } } } else throw new IllegalArgumentException("Unknown type of incoming parameter"); intent.putExtras(startParams); } ctx.startActivity(intent); } catch (Exception e) { Logger.E(TAG, "Can't run application " + appName + ": " + e.getMessage()); } }
From source file:com.android.talkback.TalkBackUpdateHelper.java
public void checkUpdate() { final int previousVersion = mSharedPreferences.getInt(PREF_APP_VERSION, -1); final PackageManager pm = mService.getPackageManager(); final int currentVersion; try {/*from w ww.jav a 2s .co m*/ final PackageInfo packageInfo = pm.getPackageInfo(mService.getPackageName(), 0); currentVersion = packageInfo.versionCode; } catch (NameNotFoundException e) { e.printStackTrace(); return; } if (previousVersion == currentVersion) { return; } final Editor editor = mSharedPreferences.edit(); editor.putInt(PREF_APP_VERSION, currentVersion); // Handle bug when updating from Revision 68 on Jelly Bean factory ROM if (needsExploreByTouchHelper(previousVersion)) { mService.addEventListener(new ExploreByTouchUpdateHelper(mService)); } // Revision 74 changes the gesture model added in revision 68. if ((previousVersion >= 68) && (previousVersion < 74)) { notifyUserOfGestureChanges(); } // Revision 84 combines the TalkBack and continuous reading breakout // menus. References to the continuous reading menu are silently // remapped to the local breakout menu. if (previousVersion < 84) { remapContinuousReadingMenu(); } // Revision 90 removes the "shake to read" checkbox preference and // replaces it with a list preference of shake velocity thresholds that // includes a default "Off" option. if (previousVersion < 90) { remapShakeToReadPref(); } // Revision 97 moved granularity selection into a local context menu, so // the up-then-down and down-then-up gestures were remapped to help // users navigate past groups of things, like web content and lists. if ((previousVersion != -1) && (previousVersion < 97)) { notifyUserOfBuiltInGestureChanges(); } // TalkBack 4.5 changes the default up and down gestures to prev/next navigation setting. if ((previousVersion != -1) && previousVersion < 40500000) { notifyUserOfBuiltInGestureChanges45(); } // Update key combo model. KeyComboManager keyComboManager = mService.getKeyComboManager(); if (keyComboManager != null) { keyComboManager.getKeyComboModel().updateVersion(previousVersion); } editor.apply(); }
From source file:org.mumod.util.HttpManager.java
private String getUserAgent() { if (mContext != null) { try {//w w w . j a v a 2s. c o m // Read package name and version number from manifest PackageManager manager = mContext.getPackageManager(); PackageInfo info = manager.getPackageInfo(mContext.getPackageName(), 0); return String.format(mContext.getString(R.string.template_user_agent), mContext.getString(R.string.app_name), info.versionName); } catch (NameNotFoundException e) { Log.e("Mustard", "Couldn't find package information in PackageManager", e); } } return "Mustard/1.0"; }
From source file:com.safecell.AccountFormActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setWindowAnimations(R.anim.null_animation); context = AccountFormActivity.this; this.initUI(); profilesRepository = new ProfilesRepository(context); createAccountButton.setOnClickListener(createAccountButtonOnclickListenr); progressDialog = new ProgressDialog(context); licenseProgressDialog = new ProgressDialog(context); licenseThread = new LicenseThread(); Intent intent = getIntent();/*from w w w .jav a 2 s.c o m*/ Bundle bundle = intent.getExtras(); callingActivity = bundle.getString("from"); handler = new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub super.handleMessage(msg); licenseProgressDialog.dismiss(); if (licenseThread.isAlive()) { licenseThread.interrupt(); licenseThread = new LicenseThread(); } if (licensekeyString == null) { message = getLicenseKey.getFailureMessage(); UIUtils.OkDialog(context, message); return; } selectLicenseFromDialog(); } }; PackageManager pm = getPackageManager(); try { //---get the package info--- PackageInfo pi = pm.getPackageInfo("com.safecell", 0); //Log.v("Version Code", "Code = "+pi.versionCode); //Log.v("Version Name", "Name = "+pi.versionName); versionName = pi.versionName; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } preferences = getSharedPreferences("AccountUniqueID", MODE_WORLD_WRITEABLE); preferences.getString("AccountUID", ""); createAccountUniqueID(SCProfile.newUniqueDeviceKey()); }