android.content.pm.PackageManager.NameNotFoundException Java Examples

The following examples show how to use android.content.pm.PackageManager.NameNotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Facebook.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Query the signature for the application that would be invoked by the
 * given intent and verify that it matches the FB application's signature.
 * 
 * @param context
 * @param packageName
 * @return true if the app's signature matches the expected signature.
 */
private boolean validateAppSignatureForPackage(Context context, String packageName) {

    PackageInfo packageInfo;
    try {
        packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
    } catch (NameNotFoundException e) {
        return false;
    }

    for (Signature signature : packageInfo.signatures) {
        if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
            return true;
        }
    }
    return false;
}
 
Example #2
Source File: SuggestionsAdapter.java    From zen4android with MIT License 6 votes vote down vote up
/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set.
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0) return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for "
                + component.flattenToShortString());
        return null;
    }
    return drawable;
}
 
Example #3
Source File: AndroidTiclManifest.java    From 365browser with Apache License 2.0 6 votes vote down vote up
ApplicationMetadata(Context context) {
  ApplicationInfo appInfo;
  try {
    // Read metadata from manifest.xml
    appInfo = context.getPackageManager()
        .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
  } catch (NameNotFoundException exception) {
    throw new RuntimeException("Cannot read own application info", exception);
  }
  ticlServiceClass = readApplicationMetadata(appInfo, TICL_SERVICE_NAME_KEY);
  listenerClass = readApplicationMetadata(appInfo, LISTENER_NAME_KEY);
  listenerServiceClass = readApplicationMetadata(appInfo, LISTENER_SERVICE_NAME_KEY);
  backgroundInvalidationListenerServiceClass =
      readApplicationMetadata(appInfo, BACKGROUND_INVALIDATION_LISTENER_SERVICE_NAME_KEY);
  gcmUpstreamServiceClass = readApplicationMetadata(appInfo, GCM_UPSTREAM_SERVICE_NAME_KEY);
}
 
Example #4
Source File: ExampleUtil.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * 获取 AppKey
 *
 * @param context
 * @return
 */
public static String getAppKey(Context context) {
    Bundle metaData = null;
    String appKey = null;
    try {
        ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
                context.getPackageName(), PackageManager.GET_META_DATA);
        if (null != ai) {
            metaData = ai.metaData;
        }
        if (null != metaData) {
            appKey = metaData.getString(KEY_APP_KEY);
            if ((null == appKey) || appKey.length() != 24) {
                appKey = null;
            }
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return appKey;
}
 
Example #5
Source File: BrowserSelectorTest.java    From AppAuth-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelect_defaultBrowserSetNoneSupporting() throws NameNotFoundException {
    // Chrome is set as the users default browser, but the version is not supporting Custom Tabs
    // BrowserSelector.getAllBrowsers will result in a list, where the Dolphin browser is the
    // first element and the other browser, in this case Firefox, as the second element in the list.
    setBrowserList(FIREFOX, CHROME);
    setBrowsersWithWarmupSupport(NO_BROWSERS);
    when(mContext.getPackageManager().resolveActivity(BROWSER_INTENT, 0))
        .thenReturn(CHROME.mResolveInfo);
    List<BrowserDescriptor> allBrowsers = BrowserSelector.getAllBrowsers(mContext);

    assertThat(allBrowsers.get(0).packageName.equals(CHROME.mPackageName));
    assertFalse(allBrowsers.get(0).useCustomTab);
    assertThat(allBrowsers.get(1).packageName.equals(FIREFOX.mPackageName));
    assertFalse(allBrowsers.get(1).useCustomTab);
}
 
Example #6
Source File: RouterServiceValidator.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check to see if the app was installed from a trusted app store.
 * @param packageName the package name of the app to be tested
 * @return whether or not the app was installed from a trusted app store
 */
public boolean wasInstalledByAppStore(String packageName){
	if(shouldOverrideInstalledFrom()){
		return true;
	}
	PackageManager packageManager = context.getPackageManager();
	try {
		final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0);
		if(TrustedAppStore.isTrustedStore(packageManager.getInstallerPackageName(applicationInfo.packageName))){
			// App was installed by trusted app store
			return true;
		}
	} catch (final NameNotFoundException e) {
		e.printStackTrace();
		return false;
	}
	return false;
}
 
Example #7
Source File: LauncherActivityInfoCompatV16.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
public Drawable getIcon(int density) {
    int iconRes = mResolveInfo.getIconResource();
    Resources resources = null;
    Drawable icon = null;
    // Get the preferred density icon from the app's resources
    if (density != 0 && iconRes != 0) {
        try {
            resources = mPm.getResourcesForApplication(mActivityInfo.applicationInfo);
            icon = resources.getDrawableForDensity(iconRes, density);
        } catch (NameNotFoundException | Resources.NotFoundException exc) {
        }
    }
    // Get the default density icon
    if (icon == null) {
        icon = mResolveInfo.loadIcon(mPm);
    }
    if (icon == null) {
        resources = Resources.getSystem();
        icon = resources.getDrawableForDensity(android.R.mipmap.sym_def_app_icon, density);
    }
    return icon;
}
 
Example #8
Source File: BrowserSelectorTest.java    From AppAuth-Android with Apache License 2.0 6 votes vote down vote up
@Test
public void testSelect_defaultBrowserNoCustomTabs() throws NameNotFoundException {
    // Firefox is set as the users default browser, but the version is not supporting Custom Tabs
    // BrowserSelector.getAllBrowsers will result in a list, where the Firefox browser is the
    // first element and the other browser, in this case Chrome, as the second element in the list.
    setBrowserList(CHROME, FIREFOX);
    setBrowsersWithWarmupSupport(CHROME);
    when(mContext.getPackageManager().resolveActivity(BROWSER_INTENT, 0))
        .thenReturn(FIREFOX.mResolveInfo);
    List<BrowserDescriptor> allBrowsers = BrowserSelector.getAllBrowsers(mContext);

    assertThat(allBrowsers.get(0).packageName.equals(FIREFOX.mPackageName));
    assertFalse(allBrowsers.get(0).useCustomTab);
    assertThat(allBrowsers.get(1).packageName.equals(CHROME.mPackageName));
    assertTrue(allBrowsers.get(1).useCustomTab);
}
 
Example #9
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public Context createPackageContextAsUser(String packageName, int flags, UserHandle user)
        throws NameNotFoundException {
    final boolean restricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;
    if (packageName.equals("system") || packageName.equals("android")) {
        return new ContextImpl(this, mMainThread, mPackageInfo, mActivityToken,
                user, restricted, mDisplay, mOverrideConfiguration);
    }

    LoadedApk pi = mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(),
            flags | CONTEXT_REGISTER_PACKAGE, user.getIdentifier());
    if (pi != null) {
        ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken,
                user, restricted, mDisplay, mOverrideConfiguration);
        if (c.mResources != null) {
            return c;
        }
    }

    // Should be a better exception.
    throw new PackageManager.NameNotFoundException(
            "Application package " + packageName + " not found");
}
 
Example #10
Source File: ManifestTools.java    From android-project-wo2b with Apache License 2.0 6 votes vote down vote up
/**
 * 获取版本信息
 * 
 * @return
 */
public static VersionInfo getVersionInfo(Context context)
{
	VersionInfo versionInfo = new VersionInfo();

	try
	{
		PackageInfo pkg = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
		versionInfo.setAppName(pkg.applicationInfo.name);
		versionInfo.setVersionCode(pkg.versionCode);
		versionInfo.setVersionName(pkg.versionName);
	}
	catch (NameNotFoundException e)
	{
		Log.E(TAG, "getVersionInfo error" + e.getMessage());
		e.printStackTrace();
	}

	return versionInfo;
}
 
Example #11
Source File: ChangeLog.java    From bankomatinfos with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 *
 * Retrieves the version names and stores the new version name in
 * SharedPreferences
 *
 * @param context
 * @param sp
 *            the shared preferences to store the last version name into
 */
public ChangeLog(Context context, SharedPreferences sp) {
    this.context = context;

    // get version numbers
    this.lastVersion = sp.getString(VERSION_KEY, NO_VERSION);
    Log.d(TAG, "lastVersion: " + lastVersion);
    try {
        this.thisVersion = context.getPackageManager().getPackageInfo(
                context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        this.thisVersion = NO_VERSION;
        Log.e(TAG, "could not get version name from manifest!");
        e.printStackTrace();
    }
    Log.d(TAG, "appVersion: " + this.thisVersion);
}
 
Example #12
Source File: SystemWebViewClient.java    From xmall with MIT License 6 votes vote down vote up
/**
 * Notify the host application that an SSL error occurred while loading a resource.
 * The host application must call either handler.cancel() or handler.proceed().
 * Note that the decision may be retained for use in response to future SSL errors.
 * The default behavior is to cancel the load.
 *
 * @param view          The WebView that is initiating the callback.
 * @param handler       An SslErrorHandler object that will handle the user's response.
 * @param error         The SSL error object.
 */
@TargetApi(8)
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

    final String packageName = parentEngine.cordova.getActivity().getPackageName();
    final PackageManager pm = parentEngine.cordova.getActivity().getPackageManager();

    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // debug = true
            handler.proceed();
            return;
        } else {
            // debug = false
            super.onReceivedSslError(view, handler, error);
        }
    } catch (NameNotFoundException e) {
        // When it doubt, lock it out!
        super.onReceivedSslError(view, handler, error);
    }
}
 
Example #13
Source File: IconCache.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Updates the entries related to the given package in memory and persistent DB.
 */
public synchronized void updateIconsForPkg(String packageName, UserHandle user) {
    removeIconsForPkg(packageName, user);
    try {
        int uninstalled = android.os.Build.VERSION.SDK_INT >= 24 ? PackageManager.MATCH_UNINSTALLED_PACKAGES : PackageManager.GET_UNINSTALLED_PACKAGES;

        PackageInfo info = mPackageManager.getPackageInfo(packageName,
                uninstalled);
        long userSerial = mUserManager.getSerialNumberForUser(user);
        for (LauncherActivityInfo app : mLauncherApps.getActivityList(packageName, user)) {
            addIconToDBAndMemCache(app, info, userSerial, false /*replace existing*/);
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return;
    }
}
 
Example #14
Source File: AboutChromePreferences.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Build the application version to be shown.  In particular, this ensures the debug build
 * versions are more useful.
 */
public static String getApplicationVersion(Context context, String version) {
    if (ChromeVersionInfo.isOfficialBuild()) {
        return version;
    }

    // For developer builds, show how recently the app was installed/updated.
    PackageInfo info;
    try {
        info = context.getPackageManager().getPackageInfo(
                context.getPackageName(), 0);
    } catch (NameNotFoundException e) {
        return version;
    }
    CharSequence updateTimeString = DateUtils.getRelativeTimeSpanString(
            info.lastUpdateTime, System.currentTimeMillis(), 0);
    return context.getString(R.string.version_with_update_time, version,
            updateTimeString);
}
 
Example #15
Source File: AbstractPluginActivity.java    From AndroidPirateBox with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupTitleApi11()
{
    CharSequence callingApplicationLabel = null;
    try
    {
        callingApplicationLabel =
                getPackageManager().getApplicationLabel(getPackageManager().getApplicationInfo(getCallingPackage(),
                                                                                               0));
    }
    catch (final NameNotFoundException e)
    {
        if (Constants.IS_LOGGABLE)
        {
            Log.e(Constants.LOG_TAG, "Calling package couldn't be found", e); //$NON-NLS-1$
        }
    }
    if (null != callingApplicationLabel)
    {
        setTitle(callingApplicationLabel);
    }
}
 
Example #16
Source File: BrowserSelectorTest.java    From AppAuth-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Browsers are expected to be in priority order, such that the default would be first.
 */
private void setBrowserList(TestBrowser... browsers) throws NameNotFoundException {
    if (browsers == null) {
        return;
    }

    List<ResolveInfo> resolveInfos = new ArrayList<>();

    for (TestBrowser browser : browsers) {
        when(mPackageManager.getPackageInfo(
                eq(browser.mPackageInfo.packageName),
                eq(PackageManager.GET_SIGNATURES)))
                .thenReturn(browser.mPackageInfo);
        resolveInfos.add(browser.mResolveInfo);
    }

    when(mPackageManager.queryIntentActivities(
            BROWSER_INTENT,
            PackageManager.GET_RESOLVED_FILTER))
            .thenReturn(resolveInfos);
}
 
Example #17
Source File: AboutActivity.java    From document-viewer with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.about);

    LayoutUtils.maximizeWindow(getWindow());

    String name = getResources().getString(R.string.app_name);
    String version = "";
    try {
        final PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        version = packageInfo.versionName;
        name = getResources().getString(packageInfo.applicationInfo.labelRes);
    } catch (final NameNotFoundException e) {
        e.printStackTrace();
    }

    final TextView title = (TextView) findViewById(R.id.about_title);
    title.setText(name + (LengthUtils.isNotEmpty(version) ? " v" + version : ""));

    final ExpandableListView view = (ExpandableListView) findViewById(R.id.about_parts);
    view.setAdapter(new PartsAdapter());
    view.expandGroup(0);
}
 
Example #18
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
@Override
public Context createApplicationContext(ApplicationInfo application, int flags)
        throws NameNotFoundException {
    LoadedApk pi = mMainThread.getPackageInfo(application, mResources.getCompatibilityInfo(),
            flags | CONTEXT_REGISTER_PACKAGE);
    if (pi != null) {
        final boolean restricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;
        ContextImpl c = new ContextImpl(this, mMainThread, pi, mActivityToken,
                new UserHandle(UserHandle.getUserId(application.uid)), restricted,
                mDisplay, mOverrideConfiguration);
        if (c.mResources != null) {
            return c;
        }
    }

    throw new PackageManager.NameNotFoundException(
            "Application package " + application.packageName + " not found");
}
 
Example #19
Source File: Stitch.java    From stitch-android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the Stitch SDK so that app clients can be created.
 *
 * @param context An Android context value.
 */
public static void initialize(final Context context) {
  if (!initialized.compareAndSet(false, true)) {
    return;
  }

  applicationContext = context.getApplicationContext();

  final String packageName = applicationContext.getPackageName();
  localAppName = packageName;

  final PackageManager manager = applicationContext.getPackageManager();
  try {
    final PackageInfo pkgInfo = manager.getPackageInfo(packageName, 0);
    localAppVersion = pkgInfo.versionName;
  } catch (final NameNotFoundException e) {
    Log.d(TAG, "Failed to get version of application, will not send in device info.");
  }

  Log.d(TAG, "Initialized android SDK");
}
 
Example #20
Source File: NavUtils.java    From guideshow with MIT License 5 votes vote down vote up
/**
 * Obtain an {@link Intent} that will launch an explicit target activity
 * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} &lt;meta-data&gt;
 * element in the application's manifest.
 *
 * @param context Context for looking up the activity component for the source activity
 * @param componentName ComponentName for the source Activity
 * @return a new Intent targeting the defined parent activity of sourceActivity
 * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid
 */
public static Intent getParentActivityIntent(Context context, ComponentName componentName)
        throws NameNotFoundException {
    String parentActivity = getParentActivityName(context, componentName);
    if (parentActivity == null) return null;

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(
            componentName.getPackageName(), parentActivity);
    final String grandparent = getParentActivityName(context, target);
    final Intent parentIntent = grandparent == null
            ? IntentCompat.makeMainActivity(target)
            : new Intent().setComponent(target);
    return parentIntent;
}
 
Example #21
Source File: InformationCollector.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
public static PackageInfo getPackageInfo(Context ctx)
{
    PackageInfo pInfo = null;
    try
    {
        pInfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0);
    }
    catch (final NameNotFoundException e)
    {
        // e1.printStackTrace();
        Log.e(DEBUG_TAG, "version of the application cannot be found", e);
    }
    return pInfo;
}
 
Example #22
Source File: AnalyticsEvent.java    From braintree_android with MIT License 5 votes vote down vote up
private String getAppVersion(Context context) {
    try {
        return context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        return "VersionUnknown";
    }
}
 
Example #23
Source File: k.java    From letv with Apache License 2.0 5 votes vote down vote up
public static boolean a(Context context) {
    try {
        return context.getPackageManager().getPackageInfo(a, 128) != null;
    } catch (NameNotFoundException e) {
        return false;
    }
}
 
Example #24
Source File: OngoingNotifPreference.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@Override
public String getText() {
    if (mName == null) {
        try {
            PackageManager pm = mContext.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(mPackage, 0);
            mName = (String) pi.applicationInfo.loadLabel(pm);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
            mName = mPackage;
        }
    }
    return mName; 
}
 
Example #25
Source File: SuggestionsAdapter.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
public Drawable getTheDrawable(Uri uri) throws FileNotFoundException {
    String authority = uri.getAuthority();
    Resources r;
    if (TextUtils.isEmpty(authority)) {
        throw new FileNotFoundException("No authority: " + uri);
    } else {
        try {
            r = mContext.getPackageManager().getResourcesForApplication(authority);
        } catch (NameNotFoundException ex) {
            throw new FileNotFoundException("No package found for authority: " + uri);
        }
    }
    List<String> path = uri.getPathSegments();
    if (path == null) {
        throw new FileNotFoundException("No path: " + uri);
    }
    int len = path.size();
    int id;
    if (len == 1) {
        try {
            id = Integer.parseInt(path.get(0));
        } catch (NumberFormatException e) {
            throw new FileNotFoundException("Single path segment is not a resource ID: " + uri);
        }
    } else if (len == 2) {
        id = r.getIdentifier(path.get(1), path.get(0), authority);
    } else {
        throw new FileNotFoundException("More than two path segments: " + uri);
    }
    if (id == 0) {
        throw new FileNotFoundException("No resource found for: " + uri);
    }
    return r.getDrawable(id);
}
 
Example #26
Source File: BrowserSelectorTest.java    From AppAuth-Android with Apache License 2.0 5 votes vote down vote up
@Test
public void testSelect_ignoreBrowsersWithoutHttpsSupport()
        throws NameNotFoundException {
    TestBrowser noHttpsBrowser =
            new TestBrowserBuilder("com.broken.browser")
                    .addAction(Intent.ACTION_VIEW)
                    .addCategory(Intent.CATEGORY_BROWSABLE)
                    .addScheme(SCHEME_HTTP)
                    .build();
    setBrowserList(DOLPHIN, noHttpsBrowser);
    setBrowsersWithWarmupSupport(noHttpsBrowser);
    checkSelectedBrowser(DOLPHIN, USE_STANDALONE);
}
 
Example #27
Source File: a.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void b(Context context, String str, String str2, int i) {
    Notification notification;
    Intent intent = new Intent(context, PushReceiver.class);
    intent.setAction(z[69]);
    intent.putExtra(z[70], true);
    intent.putExtra(z[96], str2);
    intent.putExtra(z[11], i);
    PendingIntent broadcast = PendingIntent.getBroadcast(context, 0, intent, 134217728);
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(z[68]);
    int i2 = -1;
    try {
        i2 = context.getPackageManager().getPackageInfo(context.getPackageName(), 256).applicationInfo.icon;
    } catch (NameNotFoundException e) {
    }
    if (i2 < 0) {
        i2 = 17301586;
    }
    Object obj = z[95];
    Object obj2 = z[94];
    long currentTimeMillis = System.currentTimeMillis();
    if (VERSION.SDK_INT >= 11) {
        notification = new Builder(context.getApplicationContext()).setContentTitle(obj).setContentText(obj2).setContentIntent(broadcast).setSmallIcon(i2).setTicker(str).setWhen(currentTimeMillis).getNotification();
        notification.flags = 34;
    } else {
        Notification notification2 = new Notification(i2, str, currentTimeMillis);
        notification2.flags = 34;
        m.a(notification2, context, obj, obj2, broadcast);
        notification = notification2;
    }
    if (notification != null) {
        notificationManager.notify(str.hashCode(), notification);
    }
}
 
Example #28
Source File: Application.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieve the version number of the app.
 *
 * @return the app version.
 */
public static int getVersion() {
	PackageInfo pInfo;
	try {
		pInfo = getAppContext().getPackageManager().getPackageInfo(getAppContext().getPackageName(), 0);
		return pInfo.versionCode;
	}
	catch (NameNotFoundException e) {
		Log.e(TAG, "Did not find application version", e);
		return 0;
	}
}
 
Example #29
Source File: AndroidTestOrchestrator.java    From android-test with Apache License 2.0 5 votes vote down vote up
/** Returns the package of the app under test. */
private String getTargetPackage(Bundle arguments) {
  String instrPackage = getTargetInstrPackage(arguments);
  String instrumentation = getTargetInstrumentation(arguments).split("/", -1)[1];
  PackageManager packageManager = getContext().getPackageManager();
  try {
    InstrumentationInfo instrInfo =
        packageManager.getInstrumentationInfo(
            new ComponentName(instrPackage, instrumentation), 0 /* no flags */);
    return instrInfo.targetPackage;
  } catch (NameNotFoundException e) {
    throw new IllegalStateException(
        "Package [" + instrPackage + "] cannot be found on the system.");
  }
}
 
Example #30
Source File: DataReductionPromoInfoBar.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the time at which this app was first installed in milliseconds since January 1, 1970
 * 00:00:00.0 UTC.
 *
 * @param context An Android context.
 * @return The time at which this app was first installed in milliseconds since the epoch or
 *         zero if the time cannot be retrieved.
 */
private static long getPackageInstallTime(Context context) {
    PackageInfo packageInfo;
    try {
        packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
    } catch (NameNotFoundException e) {
        packageInfo = null;
    }
    return packageInfo == null ? NO_INSTALL_TIME : packageInfo.firstInstallTime;
}