java类android.content.pm.PackageManager.NameNotFoundException的实例源码

ScreenFilterMonitorImpl.java 文件源码 项目:Nird2 阅读 43 收藏 0 点赞 0 评论 0
private boolean isPlayServices(String pkg) {
    if (!PLAY_SERVICES_PACKAGE.equals(pkg)) return false;
    try {
        PackageInfo sigs = pm.getPackageInfo(pkg, GET_SIGNATURES);
        // The genuine Play Services app should have a single signature
        Signature[] signatures = sigs.signatures;
        if (signatures == null || signatures.length != 1) return false;
        // Extract the public key from the signature
        CertificateFactory certFactory =
                CertificateFactory.getInstance("X509");
        byte[] signatureBytes = signatures[0].toByteArray();
        InputStream in = new ByteArrayInputStream(signatureBytes);
        X509Certificate cert =
                (X509Certificate) certFactory.generateCertificate(in);
        byte[] publicKeyBytes = cert.getPublicKey().getEncoded();
        String publicKey = StringUtils.toHexString(publicKeyBytes);
        return PLAY_SERVICES_PUBLIC_KEY.equals(publicKey);
    } catch (NameNotFoundException | CertificateException e) {
        if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
        return false;
    }
}
PackageUtils.java 文件源码 项目:CorePatch 阅读 43 收藏 0 点赞 0 评论 0
/**
 * get app version code
 *
 * @param context
 * @return
 */
public static int getAppVersionCode(Context context) {
    if (context != null) {
        PackageManager pm = context.getPackageManager();
        if (pm != null) {
            PackageInfo pi;
            try {
                pi = pm.getPackageInfo(context.getPackageName(), 0);
                if (pi != null) {
                    return pi.versionCode;
                }
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return -1;
}
CallHandler.java 文件源码 项目:CSipSimple 阅读 36 收藏 0 点赞 0 评论 0
@Override
public void onReceive(Context context, Intent intent) {
    if(SipManager.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {

        PendingIntent pendingIntent = null;
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        // We must handle that clean way cause when call just to 
        // get the row in account list expect this to reply correctly
        if(number != null && PhoneCapabilityTester.isPhone(context)) {
            // Build pending intent
            Intent i = new Intent(Intent.ACTION_CALL);
            i.setData(Uri.fromParts("tel", number, null));
            pendingIntent = PendingIntent.getActivity(context, 0, i, 0);
        }

        // Retrieve and cache infos from the phone app 
        if(!sPhoneAppInfoLoaded) {
            List<ResolveInfo> callers = PhoneCapabilityTester.resolveActivitiesForPriviledgedCall(context);
            if(callers != null) {
                for(final ResolveInfo caller : callers) {
                    if(caller.activityInfo.packageName.startsWith("com.android")) {
                        PackageManager pm = context.getPackageManager();
                        Resources remoteRes;
                        try {
                            // We load the resource in the context of the remote app to have a bitmap to return.
                            remoteRes = pm.getResourcesForApplication(caller.activityInfo.applicationInfo);
                            sPhoneAppBmp = BitmapFactory.decodeResource(remoteRes, caller.getIconResource());
                        } catch (NameNotFoundException e) {
                            Log.e(THIS_FILE, "Impossible to load ", e);
                        }
                        break;
                    }
                }
            }
            sPhoneAppInfoLoaded = true;
        }


        //Build the result for the row (label, icon, pending intent, and excluded phone number)
        Bundle results = getResultExtras(true);
        if(pendingIntent != null) {
            results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        }
        results.putString(Intent.EXTRA_TITLE, context.getResources().getString(R.string.use_pstn));
        if(sPhoneAppBmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, sPhoneAppBmp);
        }

        // This will exclude next time tel:xxx is raised from csipsimple treatment which is wanted
        results.putString(Intent.EXTRA_PHONE_NUMBER, number);

    }
}
IconCache.java 文件源码 项目:SimpleUILauncher 阅读 34 收藏 0 点赞 0 评论 0
/**
 * 根据ActivityInfo绘制图标
 * @param info
 * @return
 */
public Drawable getFullResIcon(ActivityInfo info) {
    Resources resources;
    try {
        resources = mPackageManager.getResourcesForApplication(
                info.applicationInfo);
    } catch (PackageManager.NameNotFoundException e) {
        resources = null;
    }
    if (resources != null) {
        int iconId = info.getIconResource();
        if (iconId != 0) {
            return getFullResIcon(resources, iconId);
        }
    }

    return getFullResDefaultActivityIcon();
}
NonBitmapDrawableResourcesTest.java 文件源码 项目:GitHub 阅读 41 收藏 0 点赞 0 评论 0
@Test
public void load_withApplicationIconResourceIdUri_asDrawable_withTransformation_nonNullDrawable()
    throws NameNotFoundException, ExecutionException, InterruptedException {
  for (String packageName : getInstalledPackages()) {
    int iconResourceId = getResourceId(packageName);

    Uri uri = new Uri.Builder()
        .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
        .authority(packageName)
        .path(String.valueOf(iconResourceId))
        .build();

    Drawable drawable = Glide.with(context)
        .load(uri)
        .apply(centerCropTransform())
        .submit()
        .get();
    assertThat(drawable).isNotNull();
  }
}
NonBitmapDrawableResourcesTest.java 文件源码 项目:GitHub 阅读 45 收藏 0 点赞 0 评论 0
@Test
public void load_withApplicationIconResourceNameUri_asDrawable_withTransform_nonNullDrawable()
    throws ExecutionException, InterruptedException, NameNotFoundException {
  for (String packageName : getInstalledPackages()) {
    int iconResourceId = getResourceId(packageName);

    Context toUse = context.createPackageContext(packageName, /*flags=*/ 0);
    Resources resources = toUse.getResources();
    Uri uri = new Uri.Builder()
        .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
        .authority(packageName)
        .path(resources.getResourceTypeName(iconResourceId))
        .path(resources.getResourceEntryName(iconResourceId))
        .path(String.valueOf(iconResourceId))
        .build();

    Drawable drawable = Glide.with(context)
        .load(uri)
        .apply(centerCropTransform())
        .submit()
        .get();
    assertThat(drawable).isNotNull();
  }
}
NonBitmapDrawableResourcesTest.java 文件源码 项目:GitHub 阅读 44 收藏 0 点赞 0 评论 0
@Test
public void load_withApplicationIconResourceNameUri_asBitmap_producesNonNullBitmap()
    throws ExecutionException, InterruptedException, NameNotFoundException {
  for (String packageName : getInstalledPackages()) {
    int iconResourceId = getResourceId(packageName);

    Context toUse = context.createPackageContext(packageName, /*flags=*/ 0);
    Resources resources = toUse.getResources();
    Uri uri = new Uri.Builder()
        .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
        .authority(packageName)
        .path(resources.getResourceTypeName(iconResourceId))
        .path(resources.getResourceEntryName(iconResourceId))
        .path(String.valueOf(iconResourceId))
        .build();

    Bitmap bitmap = Glide.with(context)
        .asBitmap()
        .load(uri)
        .submit()
        .get();
    assertThat(bitmap).isNotNull();
  }
}
SystemWebViewClient.java 文件源码 项目:localcloud_fe 阅读 41 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
X5WebViewClient.java 文件源码 项目:cordova-plugin-x5-tbs 阅读 30 收藏 0 点赞 0 评论 0
/**
 * 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);
  }
}
LauncherProvider.java 文件源码 项目:LaunchEnr 阅读 42 收藏 0 点赞 0 评论 0
/**
 * Creates workspace loader from an XML resource listed in the app restrictions.
 *
 * @return the loader if the restrictions are set and the resource exists; null otherwise.
 */
private AutoInstallsLayout createWorkspaceLoaderFromAppRestriction(AppWidgetHost widgetHost) {
    Context ctx = getContext();
    UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
    Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
    if (bundle == null) {
        return null;
    }

    String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
    if (packageName != null) {
        try {
            Resources targetResources = ctx.getPackageManager()
                    .getResourcesForApplication(packageName);
            return AutoInstallsLayout.get(ctx, packageName, targetResources,
                    widgetHost, mOpenHelper);
        } catch (NameNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }
    return null;
}
CordovaWebViewClient.java 文件源码 项目:LoRaWAN-Smart-Parking 阅读 42 收藏 0 点赞 0 评论 0
/**
 * 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 = this.cordova.getActivity().getPackageName();
    final PackageManager pm = this.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);
    }
}
Utilities.java 文件源码 项目:FlickLauncher 阅读 32 收藏 0 点赞 0 评论 0
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
    final Intent intent = new Intent(action);
    for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
        if (info.activityInfo != null &&
                (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            final String packageName = info.activityInfo.packageName;
            try {
                final Resources res = pm.getResourcesForApplication(packageName);
                return Pair.create(packageName, res);
            } catch (NameNotFoundException e) {
                Log.w(TAG, "Failed to find resources for " + packageName);
            }
        }
    }
    return null;
}
IconsManager.java 文件源码 项目:LaunchEnr 阅读 42 收藏 0 点赞 0 评论 0
Bitmap getDefaultAppDrawable(String packageName) {
    Drawable drawable = null;
    try {
        drawable = mPackageManager.getApplicationIcon(mPackageManager.getApplicationInfo(
                packageName, 0));
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    if (drawable == null) {
        return null;
    }
    if (drawable instanceof BitmapDrawable) {
        return generateBitmap(((BitmapDrawable) drawable).getBitmap());
    }
    return generateBitmap(Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888));
}
ApplicationInfoEx.java 文件源码 项目:XPrivacy 阅读 32 收藏 0 点赞 0 评论 0
public long getInstallTime(Context context) {
    if (mInstallTime == -1) {
        long now = System.currentTimeMillis();
        mInstallTime = now;
        for (String packageName : this.getPackageName())
            try {
                getPackageInfo(context, packageName);
                long time = mMapPkgInfo.get(packageName).firstInstallTime;
                if (time < mInstallTime)
                    mInstallTime = time;
            } catch (NameNotFoundException ex) {
            }
        if (mInstallTime == now)
            // no install time, so assume it is old
            mInstallTime = 0;
    }
    return mInstallTime;
}
ComponentFragment.java 文件源码 项目:buildAPKsSamples 阅读 31 收藏 0 点赞 0 评论 0
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root,
        Bundle savedInstanceState) {
    View view;

    CharSequence app_name = "NOT FOUND";
    try {
        // Load resources from UIComponent APK, not from activity APK
        Resources res = (Resources) getActivity().getPackageManager()
                .getResourcesForApplication(
                        this.getClass().getPackage().getName());
        view = inflater.inflate(res.getXml(R.layout.component), null);
        app_name = res.getText(R.string.app_name);
    } catch (NameNotFoundException e) {
        // Failed to load resources from our own APK
        e.printStackTrace();
        TextView out = new TextView(getActivity());
        out.setText(app_name);
        view = out;
    }

    return view;
}
Global.java 文件源码 项目:boohee_v5.6 阅读 42 收藏 0 点赞 0 评论 0
public static void saveVersionCode() {
    Context context = getContext();
    if (context != null) {
        try {
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context
                    .getPackageName(), 0);
            if (packageInfo != null) {
                Editor edit = context.getSharedPreferences("openSdk.pref", 0).edit();
                edit.putInt("app.vercode", packageInfo.versionCode);
                edit.commit();
            }
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
ExampleUtil.java 文件源码 项目:JPush 阅读 40 收藏 0 点赞 0 评论 0
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) {

    }
    return appKey;
}
SystemWebViewClient.java 文件源码 项目:cordova-vuetify 阅读 37 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
CondomKitTest.java 文件源码 项目:condom 阅读 38 收藏 0 点赞 0 评论 0
@Test @SuppressLint("HardwareIds") public void testNullDeviceIdKit() throws NameNotFoundException {
    final CondomContext condom = CondomContext.wrap(new ContextWrapper(context), "NullDeviceId",
            new CondomOptions().addKit(new NullDeviceIdKit()));
    final TelephonyManager tm = (TelephonyManager) condom.getSystemService(Context.TELEPHONY_SERVICE);
    assertNotNull(tm);
    assertTrue(tm.getClass().getName().startsWith(NullDeviceIdKit.class.getName()));
    final TelephonyManager app_tm = (TelephonyManager) condom.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
    assertNotNull(app_tm);
    assertTrue(app_tm.getClass().getName().startsWith(NullDeviceIdKit.class.getName()));

    assertPermission(condom, READ_PHONE_STATE, true);

    assertNull(tm.getDeviceId());
    if (SDK_INT >= LOLLIPOP) {
        if (SDK_INT >= M) assertNull(tm.getDeviceId(0));
        assertNull(tm.getImei());
        assertNull(tm.getImei(0));
        if (SDK_INT >= O) assertNull(tm.getMeid());
        if (SDK_INT >= O) assertNull(tm.getMeid(0));
    }
    assertNull(tm.getSimSerialNumber());
    assertNull(tm.getLine1Number());
    assertNull(tm.getSubscriberId());
}
a.java 文件源码 项目:ProgressManager 阅读 40 收藏 0 点赞 0 评论 0
/**
 * Obtain an {@link Intent} that will launch an explicit target activity specified by
 * this activity's logical parent. The logical parent is named in the application's manifest
 * by the {@link android.R.attr#parentActivityName parentActivityName} attribute.
 * Activity subclasses may override this method to modify the Intent returned by
 * super.getParentActivityIntent() or to implement a different mechanism of retrieving
 * the parent intent entirely.
 *
 * @return a new Intent targeting the defined parent of this activity or null if
 *         there is no valid parent.
 */
@Nullable
public Intent getParentActivityIntent() {
    final String parentName = mActivityInfo.parentActivityName;
    if (TextUtils.isEmpty(parentName)) {
        return null;
    }

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(this, parentName);
    try {
        final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0);
        final String parentActivity = parentInfo.parentActivityName;
        final Intent parentIntent = parentActivity == null
                ? Intent.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName +
                "' in manifest");
        return null;
    }
}
a.java 文件源码 项目:ProgressManager 阅读 47 收藏 0 点赞 0 评论 0
/**
 * Obtain an {@link Intent} that will launch an explicit target activity specified by
 * this activity's logical parent. The logical parent is named in the application's manifest
 * by the {@link android.R.attr#parentActivityName parentActivityName} attribute.
 * Activity subclasses may override this method to modify the Intent returned by
 * super.getParentActivityIntent() or to implement a different mechanism of retrieving
 * the parent intent entirely.
 *
 * @return a new Intent targeting the defined parent of this activity or null if
 *         there is no valid parent.
 */
@Nullable
public Intent getParentActivityIntent() {
    final String parentName = mActivityInfo.parentActivityName;
    if (TextUtils.isEmpty(parentName)) {
        return null;
    }

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(this, parentName);
    try {
        final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0);
        final String parentActivity = parentInfo.parentActivityName;
        final Intent parentIntent = parentActivity == null
                ? Intent.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName +
                "' in manifest");
        return null;
    }
}
Requirements.java 文件源码 项目:XPrivacy 阅读 38 收藏 0 点赞 0 评论 0
public static void checkCompatibility(ActivityBase context) {
    for (String packageName : cIncompatible)
        try {
            ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(packageName, 0);
            if (appInfo.enabled) {
                String name = context.getPackageManager().getApplicationLabel(appInfo).toString();

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
                alertDialogBuilder.setTitle(R.string.app_name);
                alertDialogBuilder.setMessage(String.format(context.getString(R.string.app_incompatible), name));
                alertDialogBuilder.setIcon(context.getThemed(R.attr.icon_launcher));
                alertDialogBuilder.setPositiveButton(context.getString(android.R.string.ok),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        } catch (NameNotFoundException ex) {
        }
}
rccccr.java 文件源码 项目:letv 阅读 40 收藏 0 点赞 0 评论 0
private void b0449щ0449щ0449щ() {
    PackageManager packageManager = this.bн043Dнннн.getPackageManager();
    try {
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(this.bн043Dнннн.getPackageName(), 0);
        int bЗЗ0417ЗЗЗ = bЗЗ0417ЗЗЗ();
        switch ((bЗЗ0417ЗЗЗ * (bЗ0417ЗЗЗЗ + bЗЗ0417ЗЗЗ)) % b04170417ЗЗЗЗ) {
            case 0:
                break;
            default:
                b0417ЗЗЗЗЗ = 73;
                bЗ0417ЗЗЗЗ = 43;
                break;
        }
        this.b043Dннннн = applicationInfo.loadLabel(packageManager).toString();
    } catch (NameNotFoundException e) {
        this.b043Dннннн = "NOT_FOUND";
    }
}
a.java 文件源码 项目:ProgressManager 阅读 35 收藏 0 点赞 0 评论 0
/**
 * Obtain an {@link Intent} that will launch an explicit target activity specified by
 * this activity's logical parent. The logical parent is named in the application's manifest
 * by the {@link android.R.attr#parentActivityName parentActivityName} attribute.
 * Activity subclasses may override this method to modify the Intent returned by
 * super.getParentActivityIntent() or to implement a different mechanism of retrieving
 * the parent intent entirely.
 *
 * @return a new Intent targeting the defined parent of this activity or null if
 *         there is no valid parent.
 */
@Nullable
public Intent getParentActivityIntent() {
    final String parentName = mActivityInfo.parentActivityName;
    if (TextUtils.isEmpty(parentName)) {
        return null;
    }

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(this, parentName);
    try {
        final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0);
        final String parentActivity = parentInfo.parentActivityName;
        final Intent parentIntent = parentActivity == null
                ? Intent.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName +
                "' in manifest");
        return null;
    }
}
a.java 文件源码 项目:ProgressManager 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Obtain an {@link Intent} that will launch an explicit target activity specified by
 * this activity's logical parent. The logical parent is named in the application's manifest
 * by the {@link android.R.attr#parentActivityName parentActivityName} attribute.
 * Activity subclasses may override this method to modify the Intent returned by
 * super.getParentActivityIntent() or to implement a different mechanism of retrieving
 * the parent intent entirely.
 *
 * @return a new Intent targeting the defined parent of this activity or null if
 *         there is no valid parent.
 */
@Nullable
public Intent getParentActivityIntent() {
    final String parentName = mActivityInfo.parentActivityName;
    if (TextUtils.isEmpty(parentName)) {
        return null;
    }

    // If the parent itself has no parent, generate a main activity intent.
    final ComponentName target = new ComponentName(this, parentName);
    try {
        final ActivityInfo parentInfo = getPackageManager().getActivityInfo(target, 0);
        final String parentActivity = parentInfo.parentActivityName;
        final Intent parentIntent = parentActivity == null
                ? Intent.makeMainActivity(target)
                : new Intent().setComponent(target);
        return parentIntent;
    } catch (NameNotFoundException e) {
        Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName +
                "' in manifest");
        return null;
    }
}
LocationManagerImplementation.java 文件源码 项目:Leanplum-Android-SDK 阅读 35 收藏 0 点赞 0 评论 0
private boolean isMetaDataSet() {
  Context context = Leanplum.getContext();
  try {
    ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(
        context.getPackageName(), PackageManager.GET_META_DATA);
    if (appInfo != null) {
      if (appInfo.metaData != null) {
        Object value = appInfo.metaData.get(METADATA);
        if (value != null) {
          return true;
        }
      }
    }
    return false;
  } catch (NameNotFoundException e) {
    return false;
  }
}
PreventFragment.java 文件源码 项目:prevent 阅读 39 收藏 0 点赞 0 评论 0
@Override
protected Set<AppInfo> doInBackground(Void... params) {
    PreventActivity pa = wr.get();
    Set<AppInfo> applications = new TreeSet<AppInfo>();
    if (pa == null) {
        return applications;
    }
    PackageManager pm = pa.getPackageManager();
    Map<String, Set<Long>> running = pa.getRunningProcesses();
    int i = 1;
    for (String name : mAdapter.getNames()) {
        publishProgress(++i);
        ApplicationInfo info;
        try {
            info = pm.getApplicationInfo(name, 0);
        } catch (NameNotFoundException e) { // NOSONAR
            info = null;
        }
        if (info == null || !info.enabled) {
            continue;
        }
        String label = labelLoader.loadLabel(info);
        applications.add(new AppInfo(name, label, running.get(name)).setFlags(info.flags));
    }
    return applications;
}
SMSApp.java 文件源码 项目:NoticeDog 阅读 33 收藏 0 点赞 0 评论 0
public Drawable getAppIcon() {
    try {
        return this.context.getPackageManager().getApplicationIcon(getAppPackageName());
    } catch (NameNotFoundException e) {
        return null;
    }
}
VCamera.java 文件源码 项目:meipai-Android 阅读 37 收藏 0 点赞 0 评论 0
/**
 * 获取当前应用的版本号
 * @param context
 * @return
 */
public static int getVerCode(Context context) {
    int verCode = -1;
    try {
        verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
    }
    return verCode;
}
ZenModeEventRuleSettings.java 文件源码 项目:lineagex86 阅读 32 收藏 0 点赞 0 评论 0
private static Context getContextForUser(Context context, UserHandle user) {
    try {
        return context.createPackageContextAsUser(context.getPackageName(), 0, user);
    } catch (NameNotFoundException e) {
        return null;
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号