List of usage examples for android.content.pm PackageManager getPackageInfo
public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags) throws NameNotFoundException;
From source file:com.etalio.android.EtalioBase.java
private boolean isEtalioInstalled(Context context) { PackageManager pm = context.getPackageManager(); try {/* w w w .j a v a 2 s. c o m*/ pm.getPackageInfo("com.etalio.android", PackageManager.GET_ACTIVITIES); return true; } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:com.chasetech.pcount.autoupdate.AutoUpdateApk.java
private boolean haveInternetPermissions() { Set<String> required_perms = new HashSet<String>(); required_perms.add("android.permission.INTERNET"); required_perms.add("android.permission.ACCESS_WIFI_STATE"); required_perms.add("android.permission.ACCESS_NETWORK_STATE"); PackageManager pm = context.getPackageManager(); String packageName = context.getPackageName(); int flags = PackageManager.GET_PERMISSIONS; PackageInfo packageInfo = null;//from w w w.ja v a2s.co m try { packageInfo = pm.getPackageInfo(packageName, flags); versionCode = packageInfo.versionCode; } catch (NameNotFoundException e) { // e.printStackTrace(); Log_e(TAG, e.getMessage()); } if (packageInfo.requestedPermissions != null) { for (String p : packageInfo.requestedPermissions) { //Log_v(TAG, "permission: " + p.toString()); required_perms.remove(p); } if (required_perms.size() == 0) { return true; // permissions are in order } // something is missing for (String p : required_perms) { Log_e(TAG, "required permission missing: " + p); } } Log_e(TAG, "INTERNET/WIFI access required, but no permissions are found in Manifest.xml"); return false; }
From source file:com.safecell.LoginActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login_layout); getWindow().setWindowAnimations(R.anim.null_animation); InitUi();//from w ww .j av a2 s .c om context = LoginActivity.this; if (!isTermsAcepted) dialogforWebview(); progressDialog = new ProgressDialog(context); mThread = new ProgressThread(); mThread1 = new ProgressThread1(); 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(); } handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); try { progressDialog.dismiss(); } catch (Exception e) { Log.e(TAG, "Exception while dismissing progress dialog"); e.printStackTrace(); } if (mThread.isAlive()) { mThread = new ProgressThread(); } } }; handler1 = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); progressDialog.dismiss(); if (mThread1.isAlive()) { mThread1 = new ProgressThread1(); } } }; }
From source file:com.tweetlanes.android.core.App.java
@Override public void onCreate() { Log.d("tweetlanes url fetch", "*** New run"); Log.d("AsyncTaskEx", "*** New run"); Log.d("StatusCache", "*** New run"); super.onCreate(); java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST); java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug"); try {/* w w w . ja va 2 s .com*/ PackageManager packageManager = getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0); mAppVersionName = packageInfo.versionName; List<ApplicationInfo> apps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo app : apps) { if (app.packageName != null && app.packageName.equalsIgnoreCase("com.chrislacy.actionlauncher.pro")) { mActionLauncherInstalled = true; break; } } } catch (NameNotFoundException e) { e.printStackTrace(); } mPreferences = PreferenceManager.getDefaultSharedPreferences(this); mPreferences.edit().putInt(SharedPreferencesConstants.VERSION, Constant.SHARED_PREFERENCES_VERSION); mAccounts = new ArrayList<AccountDescriptor>(); updateTwitterAccountCount(); SocialNetConstant.Type socialNetType = SocialNetConstant.Type.Twitter; AccountDescriptor currentAccountDescriptor = getCurrentAccount(); if (currentAccountDescriptor != null) { socialNetType = currentAccountDescriptor.getSocialNetType(); if (socialNetType == null) { socialNetType = SocialNetConstant.Type.Twitter; } TwitterManager.initModule(socialNetType, socialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_KEY : ConsumerKeyConstants.APPDOTNET_CONSUMER_KEY, socialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_SECRET : ConsumerKeyConstants.TWITTER_CONSUMER_SECRET, currentAccountDescriptor.getOAuthToken(), currentAccountDescriptor.getOAuthSecret(), currentAccountDescriptor.getAccountKey(), mConnectionStatusCallbacks); } else { TwitterManager.initModule(SocialNetConstant.Type.Twitter, ConsumerKeyConstants.TWITTER_CONSUMER_KEY, ConsumerKeyConstants.TWITTER_CONSUMER_SECRET, null, null, null, mConnectionStatusCallbacks); } setLaneDefinitions(socialNetType); AppSettings.initModule(this); }
From source file:com.autoupdateapk.AutoUpdateApk.java
private boolean haveInternetPermissions() { Set<String> required_perms = new HashSet<String>(); required_perms.add("android.permission.INTERNET"); required_perms.add("android.permission.ACCESS_WIFI_STATE"); required_perms.add("android.permission.ACCESS_NETWORK_STATE"); PackageManager pm = context.getPackageManager(); String packageName = context.getPackageName(); int flags = PackageManager.GET_PERMISSIONS; PackageInfo packageInfo = null;/*from ww w. java 2 s . c om*/ try { packageInfo = pm.getPackageInfo(packageName, flags); versionCode = Integer.parseInt(packageInfo.versionName); } catch (NameNotFoundException e) { Log_e(TAG, e.getMessage()); } if (packageInfo.requestedPermissions != null) { for (String p : packageInfo.requestedPermissions) { // Log_v(TAG, "permission: " + p.toString()); required_perms.remove(p); } if (required_perms.size() == 0) { return true; // permissions are in order } // something is missing for (String p : required_perms) { Log_e(TAG, "required permission missing: " + p); } } Log_e(TAG, "INTERNET/WIFI access required, but no permissions are found in Manifest.xml"); return false; }
From source file:com.abewy.android.apps.klyph.app.MainActivity.java
private void updateContent(int selection) { if (selection != oldSelection) { Bundle bundle = new Bundle(); bundle.putString(KlyphBundleExtras.ELEMENT_ID, KlyphSession.getSessionUserId()); String className = classes.get(selection); if (className.equals("com.abewy.android.apps.klyph.fragment.Chat")) { PackageManager pm = getPackageManager(); try { pm.getPackageInfo(MESSENGER_PACKAGE_NAME, PackageManager.GET_ACTIVITIES); Intent intent = getPackageManager().getLaunchIntentForPackage(MESSENGER_PACKAGE_NAME); startActivity(intent);//from w ww . j a v a 2 s .co m } catch (NameNotFoundException e) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MESSENGER_PLAY_STORE_URI)); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(intent); } } else { if (selection < navAdapter.getCount()) setTitle(navAdapter.getItem(selection)); else setTitle(KlyphSession.getSessionUserName()); Fragment fragment = Fragment.instantiate(MainActivity.this, className, bundle); if (previousFragment != null) previousFragment.onSetToBack(this); FragmentTransaction tx = getFragmentManager().beginTransaction(); tx.replace(R.id.main, fragment, FRAGMENT_TAG); tx.commitAllowingStateLoss(); ((IKlyphFragment) fragment).onSetToFront(this); previousFragment = (IKlyphFragment) fragment; navAdapter.setSelectedPosition(selection); navAdapter.notifyDataSetChanged(); oldSelection = selection; if (notificationsFragment != null) notificationsFragment.setHasOptionsMenu(false); } } }
From source file:com.abewy.android.apps.openklyph.app.MainActivity.java
private void updateContent(int selection) { if (selection != oldSelection) { Bundle bundle = new Bundle(); bundle.putString(KlyphBundleExtras.ELEMENT_ID, KlyphSession.getSessionUserId()); String className = classes.get(selection); if (className.equals("com.abewy.android.apps.openklyph.fragment.Chat")) { PackageManager pm = getPackageManager(); try { pm.getPackageInfo(MESSENGER_PACKAGE_NAME, PackageManager.GET_ACTIVITIES); Intent intent = getPackageManager().getLaunchIntentForPackage(MESSENGER_PACKAGE_NAME); startActivity(intent);//from w w w. ja v a2 s . co m } catch (NameNotFoundException e) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MESSENGER_PLAY_STORE_URI)); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(intent); } } else { if (selection < navAdapter.getCount()) setTitle(navAdapter.getItem(selection)); else setTitle(KlyphSession.getSessionUserName()); Fragment fragment = Fragment.instantiate(MainActivity.this, className, bundle); if (previousFragment != null) previousFragment.onSetToBack(this); FragmentTransaction tx = getFragmentManager().beginTransaction(); tx.replace(R.id.main, fragment, FRAGMENT_TAG); tx.commitAllowingStateLoss(); ((IKlyphFragment) fragment).onSetToFront(this); previousFragment = (IKlyphFragment) fragment; navAdapter.setSelectedPosition(selection); navAdapter.notifyDataSetChanged(); oldSelection = selection; if (notificationsFragment != null) notificationsFragment.setHasOptionsMenu(false); } } }
From source file:org.droid2droid.internal.AbstractRemoteAndroidImpl.java
public void pushMe(final Context context, final PublishListener listener, final int bufsize, final int flags, final long timeout) throws RemoteException, IOException { new AsyncTask<PublishListener, Integer, Object>() { private PublishListener listener; @Override// w ww .jav a 2 s . c o m protected Object doInBackground(PublishListener... params) { listener = params[0]; FileInputStream in = null; int fd = -1; int connid = -1; int s; byte[] buf = new byte[bufsize]; byte[] signature = null; try { PackageManager pm = context.getPackageManager(); ApplicationInfo info = Droid2DroidManagerImpl.sAppInfo; String label = context.getString(info.labelRes); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); File filename = new File(info.publicSourceDir); int versionCode = pi.versionCode; signature = pi.signatures[0].toByteArray(); long length = filename.length(); connid = getConnectionId(); if (V) Log.v(TAG_INSTALL, PREFIX_LOG + "CLI propose apk " + info.packageName); fd = proposeApk(connid, label, info.packageName, versionCode, signature, length, flags, timeout); if (fd > 0) { // TODO: ask sender before send datas if (V) Log.v(TAG_INSTALL, PREFIX_LOG + "CLI it's accepted"); in = new FileInputStream(filename); StringBuilder prog = new StringBuilder(); // TODO: multi thread for optimize read latency ? long timeoutSendFile = 30000; // FIXME: Time out pour send file en dur. long pos = 0; if (V) Log.v(TAG_INSTALL, PREFIX_LOG + "CLI send file"); while ((s = in.read(buf, 0, buf.length)) > 0) { if (V) { prog.append('*'); if (V) Log.v(TAG_INSTALL, PREFIX_LOG + "" + prog.toString()); // TODO: A garder ? } if (!sendFileData(connid, fd, buf, s, pos, length, timeoutSendFile)) { if (E) Log.e(TAG_INSTALL, PREFIX_LOG + "Impossible to send file data"); throw new RemoteException(); } pos += s; publishProgress((int) ((double) pos / length * 10000L)); } if (V) Log.v(TAG_INSTALL, PREFIX_LOG + "CLI send file done"); if (installApk(connid, label, fd, flags, timeout)) { if (V) Log.v(TAG_INSTALL, PREFIX_LOG + "CLI apk is installed"); return 1; } else { if (V) Log.v(TAG_INSTALL, PREFIX_LOG + "CLI install apk is canceled"); return new CancellationException("Install apk " + pi.packageName + " is canceled"); } } else { if (V) Log.v(TAG_INSTALL, PREFIX_LOG + "CLI install apk is accepted (" + fd + ")"); return fd; } } catch (NameNotFoundException e) { cancelCurrentUpload(timeout, fd, connid); return e; } catch (IOException e) { cancelCurrentUpload(timeout, fd, connid); return e; } catch (RemoteException e) { if (D) Log.d(TAG_INSTALL, "Impossible to push apk (" + e.getMessage() + ")", e); cancelCurrentUpload(timeout, fd, connid); return e; } finally { if (in != null) { try { in.close(); } catch (IOException e) { // Ignore } } } } private void cancelCurrentUpload(final long timeout, int fd, int connid) { if (connid != -1 && fd != -1) { try { cancelFileData(connid, fd, timeout); } catch (RemoteException e1) { // Ignore } } } @Override protected void onProgressUpdate(Integer... values) { postPublishProgress(listener, values[0]); } @Override protected void onPostExecute(Object result) { if (result instanceof Throwable) { postPublishError(listener, (Throwable) result); } else postPublishFinish(listener, ((Integer) result).intValue()); } }.execute(listener); }
From source file:cm.aptoide.pt.Aptoide.java
private void proceed() { if (sPref.getInt("version", 0) < pkginfo.versionCode) { db.UpdateTables();//from w w w . j ava 2s .co m prefEdit.putBoolean("mode", true); prefEdit.putInt("version", pkginfo.versionCode); prefEdit.commit(); } if (sPref.getString("myId", null) == null) { String rand_id = UUID.randomUUID().toString(); prefEdit.putString("myId", rand_id); prefEdit.commit(); } if (sPref.getInt("scW", 0) == 0 || sPref.getInt("scH", 0) == 0) { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); prefEdit.putInt("scW", dm.widthPixels); prefEdit.putInt("scH", dm.heightPixels); prefEdit.commit(); } if (sPref.getString("icdown", null) == null) { prefEdit.putString("icdown", "g3w"); prefEdit.commit(); } setContentView(R.layout.start); mProgress = (ProgressBar) findViewById(R.id.pbar); new Thread(new Runnable() { public void run() { Vector<ApkNode> apk_lst = db.getAll("abc"); mProgress.setMax(apk_lst.size()); PackageManager mPm; PackageInfo pkginfo; mPm = getPackageManager(); keepScreenOn.acquire(); for (ApkNode node : apk_lst) { if (node.status == 0) { try { pkginfo = mPm.getPackageInfo(node.apkid, 0); String vers = pkginfo.versionName; int verscode = pkginfo.versionCode; db.insertInstalled(node.apkid, vers, verscode); } catch (Exception e) { //Not installed anywhere... does nothing } } else { try { pkginfo = mPm.getPackageInfo(node.apkid, 0); String vers = pkginfo.versionName; int verscode = pkginfo.versionCode; db.UpdateInstalled(node.apkid, vers, verscode); } catch (Exception e) { db.removeInstalled(node.apkid); } } mProgressStatus++; // Update the progress bar mHandler.post(new Runnable() { public void run() { mProgress.setProgress(mProgressStatus); } }); } keepScreenOn.release(); Message msg = new Message(); msg.what = LOAD_TABS; startHandler.sendMessage(msg); } }).start(); }