當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。