本文整理匯總了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();
}