try { String app_ver = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { Log.e(tag, e.getMessage()); }
import android.content.pm.PackageManager.NameNotFoundException; try { String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; } catch (NameNotFoundException e) { Log.e("tag", e.getMessage()); }
public static boolean areThereMockPermissionApps(Context context) { int count = 0; PackageManager pm = context.getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo applicationInfo : packages) { try { PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS); // Get Permissions String[] requestedPermissions = packageInfo.requestedPermissions; if (requestedPermissions != null) { for (int i = 0; i < requestedPermissions.length; i++) { if (requestedPermissions[i] .equals("android.permission.ACCESS_MOCK_LOCATION") && !applicationInfo.packageName.equals(context.getPackageName())) { count++; } } } } catch (NameNotFoundException e) { Log.e("Got exception " + e.getMessage()); } } if (count > 0) return true; return false; }
try { Intent i = ctx.getPackageManager().getLaunchIntentForPackage("com.twidroid.SendTweet"); ctx.startActivity(i); } catch (NameNotFoundException e) { Log.e(TAG, e.getMessage()); }
try{ if(packageManager != null){ PackageInfo packageInfo = packageManager.getPackageInfo(activity.getPackageName(),0); txtVersion.setText(packageInfo.versionName); // get same value even make changes in manifest file. } } catch (NameNotFoundException ex){ Log.e("tag", ex.getMessage()); } txtVersion.setText("");
List<PackageInfo> applications = getPackageManager() .getInstalledPackages(0); for (PackageInfo info : applications) { long firstInstalled = info.firstInstallTime; long lastUpdate = info.lastUpdateTime; try { ApplicationInfo ai = getPackageManager().getApplicationInfo( info.applicationInfo.packageName, 0); if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0 /*Check system app*/ && firstInstalled != lastUpdate /*check for updated */) { Log.i(TAG, "Upgraded pre installed app is " + info.applicationInfo .loadLabel(getPackageManager()).toString()); } } catch (NameNotFoundException e) { Log.e("The exception is"+e.getMessage()); } }
try { Intent intent = new Intent(); intent.setClassName("package.name", "<your_package_name>"); startActivity(intent); } catch (NameNotFoundException e) { Log.e(TAG, e.getMessage()); }
public ExternalNameNotFoundException(NameNotFoundException e) { super(e.getMessage()); setRootCause(e); } }
public static String getLibraryPath(Context context, String libraryName) { String libraryPath = ""; PackageManager packageManager = context.getPackageManager(); PackageInfo packageInfo = null; if (packageManager != null) { try { packageInfo = packageManager.getPackageInfo(context.getPackageName(), PackageManager.GET_SHARED_LIBRARY_FILES); } catch (NameNotFoundException e) { logger.error(e.getMessage()); } } File libFile = getLibFileFromPackage(packageInfo.applicationInfo, libraryName); if (libFile != null) { libraryPath = libFile.getAbsolutePath(); } return libraryPath; }
boolean isExists; try { getPackageManager().getPackageInfo("com.myapp.name", PackageManager.GET_ACTIVITIES); isExists = true; } catch(NameNotFoundException e) { isExists = false; // Sep 11, 2013 8:39:47 PM Log.e("Exception", "NameNotFoundException" + String.valueOf(e.getMessage())); e.printStackTrace(); }
public class startApplicationReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { //Start your application Intent intent = new Intent(); intent.setClassName("package.name", "<your_package_name>"); startActivity(intent); } catch (NameNotFoundException e) { //You don't have the application installed Log.e(TAG, e.getMessage()); } //!!!If you WANT to repeat the start application alarm EVERY day //Comment/Remove the next 4 lines //Cancel start time alarm Intent intent = new Intent(yourActivity.this, startApplicationReceiver.class); PendingIntent startPI = PendingIntent.getBroadcast(this, 0, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(startPI); } }
pInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0); } catch (NameNotFoundException e) { Log.e(getClass().getName(), e.getMessage(), e); return "";
private static void handleClassAnnotation(PersistenceUnit ref, InjectionContainer container, Class<?> clazz) { String encName = ref.name(); if (encName == null || encName.equals("")) { throw new RuntimeException("JBoss requires name() for class level @PersistenceUnit"); } encName = "env/" + encName; if (container.getEncInjectors().containsKey(encName)) return; container.getEncInjectors().put(encName, new PuEncInjector(encName, null, ref.unitName(), "@PersistenceUnit")); try { addPUDependency(ref.unitName(), container); } catch (NameNotFoundException e) { throw new RuntimeException("Illegal @PersistenceUnit on " + clazz.getName() + " of unitname " + ref.unitName() + " :" + e.getMessage()); } }
private static void loadPersistenceContextClassAnnotation( PersistenceContext ref, InjectionContainer container, Class<?> clazz) { String encName = ref.name(); if (encName == null || encName.equals("")) { throw new RuntimeException( "JBoss requires name() for class level @PersistenceContext"); } encName = "env/" + ref.name(); if (container.getEncInjectors().containsKey(encName)) return; String error = "Unable to load class-level @PersistenceContext(" + ref.unitName() + ") on " + container.getIdentifier(); container.getEncInjectors().put(encName, new PcEncInjector(encName, ref.unitName(), ref.type(), null, error)); try { PersistenceUnitHandler.addPUDependency(ref.unitName(), container); } catch (NameNotFoundException e) { throw new RuntimeException("Illegal @PersistenceUnit on " + clazz.getName() + " of unitname " + ref.unitName() + " :" + e.getMessage()); } }
public void loadXml(X xml, InjectionContainer container) { if (xml == null) return; if (xml.getPersistenceUnitRefs() == null) return; for (PersistenceUnitReferenceMetaData ref : xml.getPersistenceUnitRefs()) { String encName = "env/" + ref.getPersistenceUnitRefName(); // we add injection target no matter what. enc injection might be overridden but // XML injection cannot be overriden Class<?> injectionType = InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections()); if (container.getEncInjectors().containsKey(encName)) return; container.getEncInjectors().put(encName, new PuEncInjector(encName, injectionType, ref.getPersistenceUnitName(), "<persistence-unit-ref>")); try { addPUDependency(ref.getPersistenceUnitName(), container); } catch (NameNotFoundException e) { throw new RuntimeException("Illegal <persistence-unit-ref> of " + ref.getPersistenceUnitRefName() + " :" + e.getMessage()); } } }
public void testSpecialUserTransactionName() throws Exception { transactionManager.shutdown(); TransactionManagerServices.getConfiguration().setJndiUserTransactionName("TM"); transactionManager = TransactionManagerServices.getTransactionManager(); Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, BitronixInitialContextFactory.class.getName()); Context ctx = new InitialContext(env); try { ctx.lookup("java:comp/UserTransaction"); fail("expected NameNotFoundException"); } catch (NameNotFoundException ex) { assertEquals("unable to find a bound object at name 'java:comp/UserTransaction'", ex.getMessage()); } assertTrue(transactionManager == ctx.lookup("TM")); try { ctx.lookup("aaa"); fail("expected NameNotFoundException"); } catch (NameNotFoundException ex) { assertEquals("unable to find a bound object at name 'aaa'", ex.getMessage()); } ctx.close(); }
public void testSpecialUserTransactionName() throws Exception { transactionManager.shutdown(); TransactionManagerServices.getConfiguration().setJndiUserTransactionName("TM"); transactionManager = TransactionManagerServices.getTransactionManager(); Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, BitronixInitialContextFactory.class.getName()); Context ctx = new InitialContext(env); try { ctx.lookup("java:comp/UserTransaction"); fail("expected NameNotFoundException"); } catch (NameNotFoundException ex) { assertEquals("unable to find a bound object at name 'java:comp/UserTransaction'", ex.getMessage()); } assertTrue(transactionManager == ctx.lookup("TM")); try { ctx.lookup("aaa"); fail("expected NameNotFoundException"); } catch (NameNotFoundException ex) { assertEquals("unable to find a bound object at name 'aaa'", ex.getMessage()); } ctx.close(); }
public void loadXml(X xml, InjectionContainer container) { if (xml == null) return; if (xml.getPersistenceUnitRefs() == null) return; for (PersistenceUnitReferenceMetaData ref : xml.getPersistenceUnitRefs()) { String encName = "env/" + ref.getPersistenceUnitRefName(); // we add injection target no matter what. enc injection might be overridden but // XML injection cannot be overriden Class<?> injectionType = InjectionUtil.injectionTarget(encName, ref, container, container.getEncInjections()); if (container.getEncInjectors().containsKey(encName)) return; container.getEncInjectors().put(encName, new RemotePuEncInjector(encName, injectionType, ref.getPersistenceUnitName(), "<persistence-unit-ref>")); try { PersistenceUnitHandler.addPUDependency(ref.getPersistenceUnitName(), container); } catch (NameNotFoundException e) { throw new RuntimeException("Illegal <persistence-unit-ref> of " + ref.getPersistenceUnitRefName() + " :" + e.getMessage()); } } }
public void testDefaultUserTransactionAndResources() throws Exception { PoolingDataSource pds = new PoolingDataSource(); pds.setMaxPoolSize(1); pds.setClassName(MockitoXADataSource.class.getName()); pds.setUniqueName("jdbc/pds"); pds.init(); Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, BitronixInitialContextFactory.class.getName()); Context ctx = new InitialContext(env); assertTrue(transactionManager == ctx.lookup("java:comp/UserTransaction")); try { ctx.lookup("aaa"); fail("expected NameNotFoundException"); } catch (NameNotFoundException ex) { assertEquals("unable to find a bound object at name 'aaa'", ex.getMessage()); } assertTrue(pds == ctx.lookup("jdbc/pds")); ctx.close(); pds.close(); }
public void testDefaultUserTransactionAndResources() throws Exception { PoolingDataSource pds = new PoolingDataSource(); pds.setMaxPoolSize(1); pds.setClassName(MockitoXADataSource.class.getName()); pds.setUniqueName("jdbc/pds"); pds.init(); Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, BitronixInitialContextFactory.class.getName()); Context ctx = new InitialContext(env); assertTrue(transactionManager == ctx.lookup("java:comp/UserTransaction")); try { ctx.lookup("aaa"); fail("expected NameNotFoundException"); } catch (NameNotFoundException ex) { assertEquals("unable to find a bound object at name 'aaa'", ex.getMessage()); } assertTrue(pds == ctx.lookup("jdbc/pds")); ctx.close(); pds.close(); }