本文整理汇总了Java中android.app.Activity.getPackageManager方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.getPackageManager方法的具体用法?Java Activity.getPackageManager怎么用?Java Activity.getPackageManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Activity
的用法示例。
在下文中一共展示了Activity.getPackageManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openOtherPage
import android.app.Activity; //导入方法依赖的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;
}
示例2: handleIntentUrl
import android.app.Activity; //导入方法依赖的package包/类
private void handleIntentUrl(String intentUrl){
try {
Intent intent=null;
if(TextUtils.isEmpty(intentUrl)||!intentUrl.startsWith(INTENT_SCHEME))
return ;
Activity mActivity=null;
if((mActivity=mWeakReference.get())==null)
return;
PackageManager packageManager =mActivity.getPackageManager();
intent = new Intent().parseUri(intentUrl, Intent.URI_INTENT_SCHEME);
ResolveInfo info = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
LogUtils.i("Info","resolveInfo:"+info+" package:"+intent.getPackage());
if (info != null) { //跳到该应用
mActivity.startActivity(intent);
return;
}
}catch (Exception e){
e.printStackTrace();
}
}
示例3: handleGitHubAction
import android.app.Activity; //导入方法依赖的package包/类
private void handleGitHubAction() {
final Activity activity = getActivity();
if (activity == null || activity.isFinishing()) {
return;
}
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/huazhouwang/Synapse"));
final PackageManager manager = activity.getPackageManager();
if (intent.resolveActivity(manager) != null) {
activity.startActivity(intent);
}
Tracker.getInstance()
.logEvent(TrackCons.About.CLICK_GITHUB);
}
示例4: handleRateAction
import android.app.Activity; //导入方法依赖的package包/类
private void handleRateAction() {
final Activity activity = getActivity();
if (activity == null || activity.isFinishing()) {
return;
}
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(APP_IN_GOOGLE_PLAY));
final PackageManager manager = activity.getPackageManager();
if (intent.resolveActivity(manager) != null) {
activity.startActivity(intent);
}
Tracker.getInstance()
.logEvent(TrackCons.About.CLICK_RATE);
}
示例5: isApplicationEnabled
import android.app.Activity; //导入方法依赖的package包/类
/**
* Checks if the application is available in this profile.
*
* @param packageName The package name
* @return True if the application is available in this profile.
*/
private boolean isApplicationEnabled(String packageName) {
Activity activity = getActivity();
PackageManager packageManager = activity.getPackageManager();
try {
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(
packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
// Return false if the app is not installed in this profile
if (0 == (applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)) {
return false;
}
// Check if the app is not hidden in this profile
DevicePolicyManager devicePolicyManager =
(DevicePolicyManager) activity.getSystemService(Activity.DEVICE_POLICY_SERVICE);
return !devicePolicyManager.isApplicationHidden(
BasicDeviceAdminReceiver.getComponentName(activity), packageName);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
示例6: getCurrentAppVersionName
import android.app.Activity; //导入方法依赖的package包/类
/**
* get current version name.
*
* @param activity activity
* @return current app version name.
*/
public static String getCurrentAppVersionName(Activity activity) {
try {
PackageManager manager = activity.getPackageManager();
PackageInfo info = manager.getPackageInfo(activity.getPackageName(), 0);
return info.versionName;
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "getCurrentAppVersionName: error: VersionName is String type.");
return "1.0";
}
}
示例7: getTitle
import android.app.Activity; //导入方法依赖的package包/类
@Nullable
private static String getTitle(@NonNull Activity activity, @NonNull String packageName) {
PackageManager pm = activity.getPackageManager();
try {
ApplicationInfo info = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
CharSequence title = pm.getApplicationLabel(info);
if (title != null) {
return title.toString();
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例8: getActivityInfo
import android.app.Activity; //导入方法依赖的package包/类
private static ActivityInfo getActivityInfo(Activity context) {
PackageManager packageManager = context.getPackageManager();
try {
return packageManager.getActivityInfo(context.getComponentName(),
PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return null;
}
示例9: canHandleByApp
import android.app.Activity; //导入方法依赖的package包/类
private static boolean canHandleByApp(Activity activity, String url) {
final PackageManager pm = activity.getPackageManager();
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(new Intent(Intent.ACTION_VIEW, Uri.parse(url)),
PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resolveInfos) {
if (TextUtils.equals(resolveInfo.resolvePackageName, activity.getPackageName()))
return true;
}
return false;
}
示例10: isSpeechRecognitionActivityPresented
import android.app.Activity; //导入方法依赖的package包/类
boolean isSpeechRecognitionActivityPresented(Activity callerActivity) {
try {
PackageManager pm = callerActivity.getPackageManager();
List activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() != 0) {
return true;
}
} catch (Exception e) {
}
return false;
}
示例11: getCurrentAppVersionCode
import android.app.Activity; //导入方法依赖的package包/类
/**
* get current version code.
*
* @param activity activity
* @return current app version code.
*/
public static int getCurrentAppVersionCode(Activity activity) {
try {
PackageManager manager = activity.getPackageManager();
PackageInfo info = manager.getPackageInfo(activity.getPackageName(), 0);
return info.versionCode;
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "getCurrentAppVersionCode: error: VersionCode is int type.");
return 1;
}
}
示例12: startForResult
import android.app.Activity; //导入方法依赖的package包/类
private static void startForResult(final Activity activity, final int requestCode, final Intent intent) {
final PackageManager pm = activity.getPackageManager();
if (pm.resolveActivity(intent, 0) != null)
activity.startActivityForResult(intent, requestCode);
else
redirectToDownload(activity);
}
示例13: onAttach
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
this.activity = activity;
this.application = (WalletApplication) activity.getApplication();
this.packageManager = activity.getPackageManager();
}
示例14: onAttach
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
this.activity = activity;
this.application = (WalletApplication) activity.getApplication();
this.config = application.getConfiguration();
this.pm = activity.getPackageManager();
}
示例15: onAttach
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void onAttach(final Activity activity) {
super.onAttach(activity);
this.application = (WalletApplication) activity.getApplication();
this.packageManager = activity.getPackageManager();
}