当前位置: 首页>>代码示例>>Java>>正文


Java NameNotFoundException类代码示例

本文整理汇总了Java中android.content.pm.PackageManager.NameNotFoundException的典型用法代码示例。如果您正苦于以下问题:Java NameNotFoundException类的具体用法?Java NameNotFoundException怎么用?Java NameNotFoundException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NameNotFoundException类属于android.content.pm.PackageManager包,在下文中一共展示了NameNotFoundException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFullResIcon

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
/**
 * 根据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();
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:23,代码来源:IconCache.java

示例2: isPlayServices

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
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;
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:23,代码来源:ScreenFilterMonitorImpl.java

示例3: getAppVersionCode

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:24,代码来源:PackageUtils.java

示例4: onReceive

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
@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);
		
	}
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:54,代码来源:CallHandler.java

示例5: load_withApplicationIconResourceNameUri_asDrawable_withTransform_nonNullDrawable

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
@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();
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:NonBitmapDrawableResourcesTest.java

示例6: load_withApplicationIconResourceNameUri_asBitmap_producesNonNullBitmap

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
@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();
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:NonBitmapDrawableResourcesTest.java

示例7: onReceivedSslError

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:34,代码来源:SystemWebViewClient.java

示例8: onReceivedSslError

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
/**
 * 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);
  }
}
 
开发者ID:zsxsoft,项目名称:cordova-plugin-x5-tbs,代码行数:34,代码来源:X5WebViewClient.java

示例9: createWorkspaceLoaderFromAppRestriction

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:28,代码来源:LauncherProvider.java

示例10: onReceivedSslError

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:34,代码来源:CordovaWebViewClient.java

示例11: findSystemApk

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
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;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:17,代码来源:Utilities.java

示例12: getDefaultAppDrawable

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
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));
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:18,代码来源:IconsManager.java

示例13: getInstallTime

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
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;
}
 
开发者ID:ukanth,项目名称:XPrivacy,代码行数:19,代码来源:ApplicationInfoEx.java

示例14: onCreateView

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
@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;
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:24,代码来源:ComponentFragment.java

示例15: saveVersionCode

import android.content.pm.PackageManager.NameNotFoundException; //导入依赖的package包/类
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();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:Global.java


注:本文中的android.content.pm.PackageManager.NameNotFoundException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。