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.mobilesolutionworks.android.http.WorksHttpClient.java
/** * Constructor of http client//w ww .jav a 2s. c o m * * @param context application context */ protected WorksHttpClient(Context context) { mContext = context.getApplicationContext(); String name = mContext.getPackageName(); try { PackageManager pm = mContext.getPackageManager(); if (pm != null) { ApplicationInfo ai = pm.getApplicationInfo(mContext.getPackageName(), 128); if ((ai != null) && (ai.metaData != null)) { name = ai.metaData.getString("user_agent"); } PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), 0); if (pi != null) { name = name + " ver-" + pi.versionName + " build-" + pi.versionCode; } } } catch (PackageManager.NameNotFoundException e) { } mName = name; }
From source file:a.dev.mobile.thread.MainActivity.java
private void startDialogAbout() { // Get app version PackageManager pm = getPackageManager(); String packageName = getPackageName(); String versionName;/* w w w.java 2 s. com*/ try { PackageInfo info = pm.getPackageInfo(packageName, 0); versionName = info.versionName; } catch (PackageManager.NameNotFoundException e) { versionName = "N/A"; } final MaterialDialog materialDialog = new MaterialDialog(this); materialDialog.setBackgroundResource(R.color.background_nav); materialDialog.setTitle(Html.fromHtml(getString(R.string.app_name_and_version, versionName))); materialDialog.setMessage( Html.fromHtml(getString(R.string.about_body, Calendar.getInstance().get(Calendar.YEAR)))); materialDialog.setCanceledOnTouchOutside(true); materialDialog.show(); }
From source file:cm.aptoide.pt.Aptoide.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); keepScreenOn = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "Full Power"); DownloadQueueServiceIntent = new Intent(getApplicationContext(), DownloadQueueService.class); startService(DownloadQueueServiceIntent); //@dsilveira #534 +10lines Check if Aptoide is already running to avoid wasting time and showing the splash ActivityManager activityManager = (ActivityManager) getApplicationContext() .getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> running = activityManager.getRunningTasks(Integer.MAX_VALUE); for (RunningTaskInfo runningTask : running) { if (runningTask.baseActivity.getClassName().equals("cm.aptoide.pt.RemoteInTab")) { //RemoteInTab is the real Aptoide Activity Message msg = new Message(); msg.what = LOAD_TABS;// w ww. j a v a2 s . co m startHandler.sendMessage(msg); return; } } Log.d("Aptoide", "******* \n Downloads will be made to: " + Environment.getExternalStorageDirectory().getPath() + "\n ********"); sPref = getSharedPreferences("aptoide_prefs", MODE_PRIVATE); prefEdit = sPref.edit(); db = new DbHandler(this); PackageManager mPm = getPackageManager(); try { pkginfo = mPm.getPackageInfo("cm.aptoide.pt", 0); } catch (NameNotFoundException e) { } requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); try { if (pkginfo.versionCode < Integer.parseInt(getXmlElement("versionCode"))) { Log.d("Aptoide-VersionCode", "Using version " + pkginfo.versionCode + ", suggest update!"); requestUpdateSelf(); } else { proceed(); } } catch (Exception e) { e.printStackTrace(); proceed(); } }
From source file:uk.org.openseizuredetector.MainActivity.java
@Override protected void onStart() { super.onStart(); SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); boolean audibleAlarm = SP.getBoolean("AudibleAlarm", true); Log.v(TAG, "onStart - auidbleAlarm = " + audibleAlarm); TextView tv;/*from w w w. j ava 2 s .c o m*/ tv = (TextView) findViewById(R.id.versionTv); 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 = getPackageManager(); if (packageManager != null) { try { PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0); versionName = packageInfo.versionName; } catch (PackageManager.NameNotFoundException e) { Log.v(TAG, "failed to find versionName"); versionName = null; } } tv.setText("OpenSeizureDetector Server Version " + versionName); if (!isServerRunning()) { Log.v(TAG, "Server not Running - Starting Server"); startServer(); } else { Log.v(TAG, "Server Already Running OK"); } // and bind to it so we can see its data bindToServer(); }
From source file:com.t2.compassionMeditation.DeviceManagerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mInstance = this; sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); //this.sendBroadcast(new Intent(BioFeedbackService.ACTION_SERVICE_START)); this.setContentView(R.layout.device_manager_activity_layout); this.findViewById(R.id.bluetoothSettingsButton).setOnClickListener(this); Resources resources = this.getResources(); AssetManager assetManager = resources.getAssets(); try {/*from w ww. ja v a 2s.co m*/ mSpineManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources); } catch (InstantiationException e) { Log.e(TAG, this.getClass().getSimpleName() + " Exception creating SPINE manager: " + e.toString()); e.printStackTrace(); } // ... then we need to register a SPINEListener implementation to the SPINE manager instance // to receive sensor node data from the Spine server // (I register myself since I'm a SPINEListener implementation!) mSpineManager.addListener(this); // Create a broadcast receiver. Note that this is used ONLY for command messages from the service // All data from the service goes through the mail SPINE mechanism (received(Data data)). // See public void received(Data data) this.mCommandReceiver = new SpineReceiver(this); // Set up filter intents so we can receive broadcasts IntentFilter filter = new IntentFilter(); filter.addAction("com.t2.biofeedback.service.status.BROADCAST"); filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(BioFeedbackService.ACTION_STATUS_BROADCAST); this.registerReceiver(this.mCommandReceiver, filter); // Tell the bluetooth service to send us a list of bluetooth devices and system status // Response comes in public void onStatusReceived(BioFeedbackStatus bfs) STATUS_PAIRED_DEVICES mSpineManager.pollBluetoothDevices(); // this.deviceManager = DeviceManager.getInstance(this.getBaseContext(), null); this.deviceList = (ListView) this.findViewById(R.id.list); this.deviceListAdapter = new ManagerItemAdapter(this, R.layout.manager_item); this.deviceList.setAdapter(this.deviceListAdapter); this.bluetoothDisabledDialog = new AlertDialog.Builder(this).setMessage("Bluetooth is not enabled.") .setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }).setPositiveButton("Setup Bluetooth", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startBluetoothSettings(); } }).create(); try { PackageManager packageManager = this.getPackageManager(); PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0); mVersionName = info.versionName; Log.i(TAG, this.getClass().getSimpleName() + " Spine server Test Application Version " + mVersionName); } catch (NameNotFoundException e) { Log.e(TAG, this.getClass().getSimpleName() + e.toString()); } }
From source file:com.brq.wallet.activity.modern.ModernMain.java
private void shareTransactionHistory() { WalletAccount account = _mbwManager.getSelectedAccount(); MetadataStorage metaData = _mbwManager.getMetadataStorage(); try {/*from www. j a va2 s .c om*/ String fileName = "MyceliumExport_" + System.currentTimeMillis() + ".csv"; File historyData = DataExport.getTxHistoryCsv(account, metaData, getFileStreamPath(fileName)); PackageManager packageManager = Preconditions.checkNotNull(getPackageManager()); PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_PROVIDERS); for (ProviderInfo info : packageInfo.providers) { if (info.name.equals("android.support.v4.content.FileProvider")) { String authority = info.authority; Uri uri = FileProvider.getUriForFile(this, authority, historyData); Intent intent = ShareCompat.IntentBuilder.from(this).setStream(uri) // uri from FileProvider .setType("text/plain") .setSubject(getResources().getString(R.string.transaction_history_title)) .setText(getResources().getString(R.string.transaction_history_title)).getIntent() .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); List<ResolveInfo> resInfoList = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); } startActivity(Intent.createChooser(intent, getResources().getString(R.string.share_transaction_history))); } } } catch (IOException e) { _toaster.toast("Export failed. Check your logs", false); e.printStackTrace(); } catch (PackageManager.NameNotFoundException e) { _toaster.toast("Export failed. Check your logs", false); e.printStackTrace(); } }
From source file:com.yozio.android.YozioHelper.java
private void setAppVersion() { try {/* ww w. j a v a 2s. c o m*/ PackageManager manager = context.getPackageManager(); PackageInfo packageInfo = manager.getPackageInfo(context.getPackageName(), 0); appVersion = packageInfo.versionName; } catch (Exception e) { } }
From source file:com.t2.biofeedback.BioFeedbackService.java
@Override public void onCreate() { super.onCreate(); String version = ""; try {/*from w w w .j a va2s . c o m*/ PackageManager packageManager = this.getPackageManager(); PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0); version = info.versionName; } catch (NameNotFoundException e) { Log.e(TAG, e.toString()); } Log.d(TAG, this.getClass().getSimpleName() + ".onCreate(), Version " + version); this.deviceManager = DeviceManager.getInstance(this.getBaseContext(), mServerListeners); this.manageDeviceThread = new ManageDeviceThread(); this.manageDeviceThread.start(); }
From source file:com.t2.biofeedback.BioFeedbackService.java
@Override public void onDestroy() { super.onDestroy(); String version = ""; try {/*www . ja v a 2s . c o m*/ PackageManager packageManager = this.getPackageManager(); PackageInfo info = packageManager.getPackageInfo(this.getPackageName(), 0); version = info.versionName; } catch (NameNotFoundException e) { Log.e(TAG, e.toString()); } Log.d(TAG, this.getClass().getSimpleName() + ".onDestroy(), Version " + version); this.manageDeviceThread.setRun(false); this.deviceManager.closeAll(); // this.deviceManager = null; }
From source file:com.grass.caishi.cc.MyApplication.java
public int getVersionCode()// ??(?) { try {//from w w w. j a va 2s. co m PackageManager manager = this.getPackageManager(); PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0); return info.versionCode; } catch (Exception e) { return 0; } /* * try { PackageInfo pi=context.getPackageManager().getPackageInfo(context .getPackageName(), 0); return pi.versionCode; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } */ }