本文整理汇总了Java中android.content.pm.PackageManager.resolveActivity方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.resolveActivity方法的具体用法?Java PackageManager.resolveActivity怎么用?Java PackageManager.resolveActivity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.resolveActivity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: redirectToDownload
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private static void redirectToDownload(final Context context) {
Toast.makeText(context, "No Bitcoin application found.\nPlease install Bitcoin Wallet.", Toast.LENGTH_LONG)
.show();
final Intent marketIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("market://details?id=com.okwallet"));
final Intent binaryIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://github.com/bitcoin-wallet/bitcoin-wallet/releases"));
final PackageManager pm = context.getPackageManager();
if (pm.resolveActivity(marketIntent, 0) != null)
context.startActivity(marketIntent);
else if (pm.resolveActivity(binaryIntent, 0) != null)
context.startActivity(binaryIntent);
// else out of luck
}
示例2: convertToLauncherActivityIfPossible
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Tries to create a new PendingInstallShortcutInfo which represents the same target,
* but is an app target and not a shortcut.
* @return the newly created info or the original one.
*/
private static PendingInstallShortcutInfo convertToLauncherActivityIfPossible(
PendingInstallShortcutInfo original) {
if (original.isLauncherActivity()) {
// Already an activity target
return original;
}
if (!Utilities.isLauncherAppTarget(original.launchIntent)
|| !original.user.equals(UserHandleCompat.myUserHandle())) {
// We can only convert shortcuts which point to a main activity in the current user.
return original;
}
PackageManager pm = original.mContext.getPackageManager();
ResolveInfo info = pm.resolveActivity(original.launchIntent, 0);
if (info == null) {
return original;
}
// Ignore any conflicts in the label name, as that can change based on locale.
LauncherActivityInfoCompat launcherInfo = LauncherActivityInfoCompat
.fromResolveInfo(info, original.mContext);
return new PendingInstallShortcutInfo(launcherInfo, original.mContext);
}
示例3: openOtherPage
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean openOtherPage(String intentUrl) {
try {
Intent intent;
Activity mActivity = null;
if ((mActivity = mWeakReference.get()) == null)
return true;
PackageManager packageManager = mActivity.getPackageManager();
intent = new Intent().parseUri(intentUrl, Intent.URI_INTENT_SCHEME);
ResolveInfo info = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
LogUtils.i(TAG, "resolveInfo:" + info + " package:" + intent.getPackage());
if (info != null) { //跳到该应用
mActivity.startActivity(intent);
return true;
}
} catch (Throwable ignore) {
if (LogUtils.isDebug()) {
ignore.printStackTrace();
}
}
return false;
}
示例4: validateAppSignatureForIntent
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean validateAppSignatureForIntent(Context context, Intent intent) {
PackageManager pm = context.getPackageManager();
ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
if (resolveInfo == null) {
return false;
}
try {
for (Signature signature : pm.getPackageInfo(resolveInfo.activityInfo.packageName,
64).signatures) {
if (WEIBO_SIGNATURE.equals(signature.toCharsString())) {
return true;
}
}
return false;
} catch (NameNotFoundException e) {
return false;
}
}
示例5: isActivityExists
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 判断是否存在Activity
*
* @param packageName 包名
* @param className activity全路径类名
* @return {@code true}: 是<br>{@code false}: 否
*/
public static boolean isActivityExists(String packageName, String className) {
Intent intent = new Intent();
intent.setClassName(packageName, className);
PackageManager packageManager = ContextUtils.getContext()
.getPackageManager();
return !(packageManager.resolveActivity(intent, 0) == null ||
intent.resolveActivity(packageManager) == null ||
packageManager.queryIntentActivities(intent, 0)
.isEmpty());
}
示例6: onLongClick
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public boolean onLongClick(View arg0) {
//
if (mSettings.getBoolean("use_as_lock_main", false)) {
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
Intent i = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
PackageManager pm = getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
Intent intent = new Intent();
intent.setComponent(new ComponentName(
mInfo.activityInfo.packageName, mInfo.activityInfo.name));
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
return true;
}
示例7: findKnownBrowsers
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private void findKnownBrowsers(PackageManager packageManager, Map<String, ActivityInfo> browsers, @NonNull Uri uri) {
for (final KnownBrowser browser : KnownBrowser.values()) {
if (browsers.containsKey(browser.packageName)) {
continue;
}
// resolveActivity() can be slow if the package isn't installed (e.g. 200ms on an N6 with a bad WiFi connection).
// Hence we query if the package is installed first, and only call resolveActivity for installed packages.
// getPackageInfo() is fast regardless of a package being installed
try {
// We don't need the result, we only need to detect when the package doesn't exist
packageManager.getPackageInfo(browser.packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
continue;
}
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setPackage(browser.packageName);
final ResolveInfo info = packageManager.resolveActivity(intent, 0);
if (info == null || info.activityInfo == null) {
continue;
}
if (!info.activityInfo.exported) {
continue;
}
browsers.put(info.activityInfo.packageName, info.activityInfo);
}
}
示例8: initialize
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private static void initialize(Context context) {
final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
sIsPhone = (telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE);
//sIsSipPhone = sIsPhone && SipManager.isVoipSupported(context);
Intent pIntent = getPriviledgedIntent("123");
callIntents = getPossibleActivities(context, pIntent);
PackageManager pm = context.getPackageManager();
defaultCallIntent = pm.resolveActivity(pIntent, PackageManager.MATCH_DEFAULT_ONLY);
sIsInitialized = true;
}
示例9: onCreate
import android.content.pm.PackageManager; //导入方法依赖的package包/类
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_correction);
final Context context = getActivity();
final PackageManager pm = context.getPackageManager();
final Preference dictionaryLink = findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
final Intent intent = dictionaryLink.getIntent();
intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName());
final int number = pm.queryIntentActivities(intent, 0).size();
if (0 >= number) {
removePreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
}
final Preference editPersonalDictionary =
findPreference(Settings.PREF_EDIT_PERSONAL_DICTIONARY);
final Intent editPersonalDictionaryIntent = editPersonalDictionary.getIntent();
final ResolveInfo ri = USE_INTERNAL_PERSONAL_DICTIONARY_SETTINGS ? null
: pm.resolveActivity(
editPersonalDictionaryIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (ri == null) {
overwriteUserDictionaryPreference(editPersonalDictionary);
}
mUseContactsPreference = (SwitchPreference) findPreference(Settings.PREF_KEY_USE_CONTACTS_DICT);
turnOffUseContactsIfNoPermission();
}
示例10: getPackageNameToUse
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Goes through all apps that handle VIEW intents and have a warmup service. Picks
* the one chosen by the user if there is one, otherwise makes a best effort to return a
* valid package name.
*
* This is <strong>not</strong> threadsafe.
*
* @param context {@link Context} to use for accessing {@link PackageManager}.
* @return The package name recommended to use for connecting to custom tabs related components.
*/
public static String getPackageNameToUse(Context context) {
if (sPackageNameToUse != null) return sPackageNameToUse;
PackageManager pm = context.getPackageManager();
// Get default VIEW intent handler.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
String defaultViewHandlerPackageName = null;
if (defaultViewHandlerInfo != null) {
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
}
// Get all apps that can handle VIEW intents.
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent();
serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName);
if (pm.resolveService(serviceIntent, 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
}
}
// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
// and service calls.
if (packagesSupportingCustomTabs.isEmpty()) {
sPackageNameToUse = null;
} else if (packagesSupportingCustomTabs.size() == 1) {
sPackageNameToUse = packagesSupportingCustomTabs.get(0);
} else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
&& !hasSpecializedHandlerIntents(context, activityIntent)
&& packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
sPackageNameToUse = defaultViewHandlerPackageName;
} else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
sPackageNameToUse = STABLE_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
sPackageNameToUse = BETA_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
sPackageNameToUse = DEV_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
sPackageNameToUse = LOCAL_PACKAGE;
}
return sPackageNameToUse;
}
示例11: getPackageNameToUse
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static String getPackageNameToUse(Context context) {
if (sPackageNameToUse != null) return sPackageNameToUse;
PackageManager pm = context.getPackageManager();
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
String defaultViewHandlerPackageName = null;
if (defaultViewHandlerInfo != null) {
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
}
// Get all apps that can handle VIEW intents.
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent();
serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName);
if (pm.resolveService(serviceIntent, 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
}
}
// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
// and service calls.
if (packagesSupportingCustomTabs.isEmpty()) {
sPackageNameToUse = null;
} else if (packagesSupportingCustomTabs.size() == 1) {
sPackageNameToUse = packagesSupportingCustomTabs.get(0);
} else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
&& !hasSpecializedHandlerIntents(context, activityIntent)
&& packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
sPackageNameToUse = defaultViewHandlerPackageName;
} else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
sPackageNameToUse = STABLE_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
sPackageNameToUse = BETA_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
sPackageNameToUse = DEV_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
sPackageNameToUse = LOCAL_PACKAGE;
}
return sPackageNameToUse;
}
示例12: getIcon
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Get Activity icon
*/
public static Drawable getIcon(PackageManager pkgManager, String pkgName, String activity) {
if (pkgManager == null || TextUtils.isEmpty(pkgName) || TextUtils.isEmpty(activity)) {
return null;
}
Intent intent = new Intent();
intent.setClassName(pkgName, activity);
ResolveInfo resolveInfo = pkgManager.resolveActivity(intent, 0);
if (resolveInfo != null) {
return resolveInfo.loadIcon(pkgManager);
}
return null;
}
示例13: hasEqualizer
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private boolean hasEqualizer() {
final Intent effects = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
PackageManager pm = getActivity().getPackageManager();
ResolveInfo ri = pm.resolveActivity(effects, 0);
return ri != null;
}
示例14: hasEffectsPanel
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static boolean hasEffectsPanel(final Activity activity) {
final PackageManager packageManager = activity.getPackageManager();
return packageManager.resolveActivity(createEffectsIntent(),
PackageManager.MATCH_DEFAULT_ONLY) != null;
}
示例15: isInstallApp
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* 判断App是否安装
*
* @param context 上下文
* @param action action
* @param category category
* @return {@code true}: 已安装<br>{@code false}: 未安装
*/
public static boolean isInstallApp(Context context, final String action, final String category) {
Intent intent = new Intent(action);
intent.addCategory(category);
PackageManager pm = context.getPackageManager();
ResolveInfo info = pm.resolveActivity(intent, 0);
return info != null;
}