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


Java Activity.getPackageManager方法代码示例

本文整理汇总了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;
}
 
开发者ID:Justson,项目名称:AgentWebX5,代码行数:23,代码来源:DefaultWebClient.java

示例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();
    }


}
 
开发者ID:Justson,项目名称:AgentWebX5,代码行数:25,代码来源:DefaultWebClient.java

示例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);
}
 
开发者ID:huazhouwang,项目名称:Synapse,代码行数:18,代码来源:AboutDialog.java

示例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);
}
 
开发者ID:huazhouwang,项目名称:Synapse,代码行数:18,代码来源:AboutDialog.java

示例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;
    }
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:26,代码来源:BasicManagedProfileFragment.java

示例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";
    }
}
 
开发者ID:shenhuanet,项目名称:AndroidOpen,代码行数:18,代码来源:FirUtil.java

示例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;
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:15,代码来源:BookmarkSettingsFragment.java

示例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;
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:11,代码来源:AppTools.java

示例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;
}
 
开发者ID:mecid,项目名称:robird-reborn,代码行数:13,代码来源:LinkUtils.java

示例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;
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:12,代码来源:SpeechRecognitionShield.java

示例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;
    }
}
 
开发者ID:shenhuanet,项目名称:AndroidOpen,代码行数:18,代码来源:FirUtil.java

示例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);
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:8,代码来源:BitcoinIntegration.java

示例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();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:9,代码来源:AlertDialogsFragment.java

示例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();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:10,代码来源:SettingsFragment.java

示例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();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:8,代码来源:AboutFragment.java


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