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


Java ComponentName.getPackageName方法代码示例

本文整理汇总了Java中android.content.ComponentName.getPackageName方法的典型用法代码示例。如果您正苦于以下问题:Java ComponentName.getPackageName方法的具体用法?Java ComponentName.getPackageName怎么用?Java ComponentName.getPackageName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.ComponentName的用法示例。


在下文中一共展示了ComponentName.getPackageName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getSuppressorCaption

import android.content.ComponentName; //导入方法依赖的package包/类
private String getSuppressorCaption(ComponentName suppressor) {
    final PackageManager pm = mContext.getPackageManager();
    try {
        final ServiceInfo info = pm.getServiceInfo(suppressor, 0);
        if (info != null) {
            final CharSequence seq = info.loadLabel(pm);
            if (seq != null) {
                final String str = seq.toString().trim();
                if (str.length() > 0) {
                    return str;
                }
            }
        }
    } catch (Throwable e) {
        Log.w(TAG, "Error loading suppressor caption", e);
    }
    return suppressor.getPackageName();
}
 
开发者ID:ric96,项目名称:lineagex86,代码行数:19,代码来源:SoundSettings.java

示例2: handleInstallShortcutIntent

import android.content.ComponentName; //导入方法依赖的package包/类
private Intent handleInstallShortcutIntent(Intent intent) {
    Intent shortcut = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (shortcut != null) {
        ComponentName component = shortcut.resolveActivity(VirtualCore.getPM());
        if (component != null) {
            String pkg = component.getPackageName();
            Intent newShortcutIntent = new Intent();
            newShortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
            newShortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
            newShortcutIntent.putExtra("_VA_|_intent_", shortcut);
            newShortcutIntent.putExtra("_VA_|_uri_", shortcut.toUri(0));
            newShortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
            intent.removeExtra(Intent.EXTRA_SHORTCUT_INTENT);
            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newShortcutIntent);

            Intent.ShortcutIconResource icon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            if (icon != null && !TextUtils.equals(icon.packageName, getHostPkg())) {
                try {
                    Resources resources = VirtualCore.get().getResources(pkg);
                    int resId = resources.getIdentifier(icon.resourceName, "drawable", pkg);
                    if (resId > 0) {
                        //noinspection deprecation
                        Drawable iconDrawable = resources.getDrawable(resId);
                        Bitmap newIcon = BitmapUtils.drawableToBitmap(iconDrawable);
                        if (newIcon != null) {
                            intent.removeExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
                            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newIcon);
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return intent;
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:38,代码来源:MethodProxies.java

示例3: get

import android.content.ComponentName; //导入方法依赖的package包/类
/**
 * -     * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX}
 * -     * provided by the same package which is set to be global search activity.
 * -     * If widgetCategory is not supported, or no such widget is found, returns the first widget
 * -     * provided by the package.
 * -
 */
public static AppWidgetProviderInfo get(Context context) {
    SearchManager searchManager =
            (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
    ComponentName searchComponent = searchManager.getGlobalSearchActivity();
    if (searchComponent == null) return null;
    String providerPkg = searchComponent.getPackageName();

    AppWidgetProviderInfo defaultWidgetForSearchPackage = null;

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) {
        if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) {
            if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
                return info;
            } else if (defaultWidgetForSearchPackage == null) {
                defaultWidgetForSearchPackage = info;
            }
        }
    }
    return defaultWidgetForSearchPackage;
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:29,代码来源:SearchWidgetProvider.java

示例4: extractCallerAuthDomain

import android.content.ComponentName; //导入方法依赖的package包/类
private boolean extractCallerAuthDomain() {
    ComponentName callingActivity = getCallingActivity();
    if (callingActivity == null) {
        Log.w(LOG_TAG, "No calling activity found for save call");
        return false;
    }

    String callingPackage = callingActivity.getPackageName();
    AuthenticationDomain authDomain =
            AuthenticationDomain.fromPackageName(this, callingPackage);

    if (null == authDomain) {
        return false;
    }

    mCallerAuthDomain = authDomain;
    return true;
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:19,代码来源:HintPickerActivity.java

示例5: verifyCaller

import android.content.ComponentName; //导入方法依赖的package包/类
private boolean verifyCaller() {
    final ComponentName callingActivity = getCallingActivity();
    if (callingActivity == null) {
        Log.w(LOG_TAG, "No calling activity found for save call");
        return false;
    }

    // TODO: a more complete implementation would need to expand this to the full set of
    // affiliated apps and sites, though it is generally unusual for an app to save a
    // credential for any authentication domain other than those it can directly identify as.
    mCallingPackage = callingActivity.getPackageName();
    mAuthDomainForApp = AuthenticationDomain.fromPackageName(this, mCallingPackage);

    final AuthenticationDomain authDomain = mRequest.getCredential().getAuthenticationDomain();
    if (!authDomain.equals(mAuthDomainForApp)) {
        Log.w(LOG_TAG, "App " + mCallingPackage
                + " is not provably associated to authentication domain "
                + authDomain
                + " for the credential to be saved.");
        return false;
    }

    return true;
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:25,代码来源:SaveCredentialActivity.java

示例6: getApp

import android.content.ComponentName; //导入方法依赖的package包/类
public AppLauncher getApp(ComponentName appname) {

        String actvname = appname.getClassName();
        String pkgname =  appname.getPackageName();

        AppLauncher appLauncher = null;
        SQLiteDatabase db = this.getReadableDatabase();

        Cursor cursor = db.query(APP_TABLE, appcolumns, ACTVNAME + "=? and " + PKGNAME + "=?", new String[]{actvname, pkgname}, null, null, null);
        try {
            if (cursor.moveToNext()) { //ACTVNAME, PKGNAME, LABEL, CATID
                //pkgname = cursor.getString(1);
                String label = cursor.getString(cursor.getColumnIndex(LABEL));
                String catID = cursor.getString(cursor.getColumnIndex(CATID));
                boolean widget = cursor.getShort(cursor.getColumnIndex(ISWIDGET)) == 1;
                String customlabel = cursor.getString(cursor.getColumnIndex(CUSTOMLABEL));

                // Log.d("LaunchDB", "getApp " + pkgname + " " + catID);
                appLauncher = AppLauncher.createAppLauncher(actvname, pkgname, customlabel==null?label:customlabel, catID, widget);
            }
        } finally {
            cursor.close();
        }
        return appLauncher;
    }
 
开发者ID:quaap,项目名称:LaunchTime,代码行数:26,代码来源:DB.java

示例7: schedule

import android.content.ComponentName; //导入方法依赖的package包/类
@Override
public int schedule(JobInfo job) throws RemoteException {
    int vuid = VBinder.getCallingUid();
    int id = job.getId();
    ComponentName service = job.getService();
    JobId jobId = new JobId(vuid, service.getPackageName(), id);
    JobConfig config = mJobStore.get(jobId);
    if (config == null) {
        config = new JobConfig(mGlobalJobId++, service.getClassName(), job.getExtras());
        mJobStore.put(jobId, config);
    } else {
        config.serviceName = service.getClassName();
        config.extras = job.getExtras();
    }
    saveJobs();
    mirror.android.app.job.JobInfo.jobId.set(job, config.virtualJobId);
    mirror.android.app.job.JobInfo.service.set(job, mJobProxyComponent);
    return mScheduler.schedule(job);
}
 
开发者ID:codehz,项目名称:container,代码行数:20,代码来源:VJobSchedulerService.java

示例8: isInSysInstallPage

import android.content.ComponentName; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static boolean isInSysInstallPage() {
    String strTopPName = null;
    Context context = ContextUtils.getApplicationContext();
    if (context == null) {
        return false;
    }
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    if (Build.VERSION.SDK_INT > 20) {
        final List<ActivityManager.RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
        if (processInfos != null && processInfos.size() > 0) {
            for (ActivityManager.RunningAppProcessInfo processInfo : processInfos) {
                if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    if (ReflectUtils.getIntField(processInfo, "flags") == 4 && processInfo.pkgList.length == 1) {
                        strTopPName = processInfo.pkgList[0];
                        break;
                    }
                }
            }
        }
    } else {
        //noinspection deprecation
        List<ActivityManager.RunningTaskInfo> runningTaskInfos = am.getRunningTasks(1);
        if (runningTaskInfos != null && !runningTaskInfos.isEmpty()) {
            ComponentName componentName = runningTaskInfos.get(0).topActivity;
            if (componentName != null && componentName.getPackageName() != null) {
                strTopPName = componentName.getPackageName();
            }
        }
    }
    logPrint("isInSysInstallPage : strTopPName=" + strTopPName);
    return MyAccessibility.packages[0].equalsIgnoreCase(strTopPName);
}
 
开发者ID:miLLlulei,项目名称:Accessibility,代码行数:35,代码来源:InstallAccessibility.java

示例9: reStart

import android.content.ComponentName; //导入方法依赖的package包/类
/**
 * 重新启动
 */
public void reStart()
{
	ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
	AlarmManager mgr = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
	List<RunningTaskInfo> taskInfos = am.getRunningTasks(Integer.MAX_VALUE);
	RunningTaskInfo taskInfo = null;
	ComponentName baseActivity = null;
	String pkgName = null;

	for (int i = 0, len = taskInfos.size(); i < len; i++)
	{
		taskInfo = taskInfos.get(i);
		baseActivity = taskInfo.baseActivity;
		pkgName = baseActivity.getPackageName();
		if (pkgName.equalsIgnoreCase(mContext.getPackageName()))
		{
			ComponentName topActivity = taskInfo.topActivity;
			if (!topActivity.getClassName().equalsIgnoreCase(baseActivity.getClassName()))
			{

				Intent intent = new Intent();
				intent.setClassName(mContext, baseActivity.getClassName());
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
				PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent,
						Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
				mgr.set(AlarmManager.RTC, System.currentTimeMillis(), pendingIntent);
			}

			return;
		}
	}
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:36,代码来源:CrashHandler.java

示例10: handleBadger

import android.content.ComponentName; //导入方法依赖的package包/类
@Override
public BadgerInfo handleBadger(Intent intent) {
    BadgerInfo info = new BadgerInfo();
    String componentName = intent.getStringExtra(getComponentKey());
    ComponentName component = ComponentName.unflattenFromString(componentName);
    if (component != null) {
        info.packageName = component.getPackageName();
        info.className = component.getClassName();
        info.badgerCount = intent.getIntExtra(getCountKey(), 0);
        return info;
    }
    return null;
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:14,代码来源:BroadcastBadger2.java

示例11: getCallingPackageName

import android.content.ComponentName; //导入方法依赖的package包/类
@Nullable
private String getCallingPackageName() {
	ComponentName componentName = getActivity().getCallingActivity();
	String packageName = null;
	if (componentName != null) {
		packageName = componentName.getPackageName();
	}
	return packageName;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:10,代码来源:PanicPreferencesFragment.java

示例12: currentAppPackageNameOnForeground

import android.content.ComponentName; //导入方法依赖的package包/类
/**
 * 慎重使用此函数<br/>
 * GET_TASK was deprecated in API level 21. No longer enforced
 */
public static String currentAppPackageNameOnForeground(final Context context) {
	try {
		ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
		List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
		if (!tasks.isEmpty()) {
			ComponentName topActivity = tasks.get(0).topActivity;
			return topActivity.getPackageName();
		}
	}catch (Exception ex){
		ex.printStackTrace();
	}
	return "";
}
 
开发者ID:waylife,项目名称:ViewDebugHelper,代码行数:18,代码来源:ActivityHelper.java

示例13: openURL

import android.content.ComponentName; //导入方法依赖的package包/类
/**
 * Starts a corresponding external activity for the given URL.
 *
 * For example, if the URL is "https://www.facebook.com", the system browser will be opened,
 * or the "choose application" dialog will be shown.
 *
 * @param url the URL to open
 */
@ReactMethod
public void openURL(String url, Promise promise) {
  if (url == null || url.isEmpty()) {
    promise.reject(new JSApplicationIllegalArgumentException("Invalid URL: " + url));
    return;
  }

  try {
    Activity currentActivity = getCurrentActivity();
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

    String selfPackageName = getReactApplicationContext().getPackageName();
    ComponentName componentName = intent.resolveActivity(
      getReactApplicationContext().getPackageManager());
    String otherPackageName = (componentName != null ? componentName.getPackageName() : "");

    // If there is no currentActivity or we are launching to a different package we need to set
    // the FLAG_ACTIVITY_NEW_TASK flag
    if (currentActivity == null || !selfPackageName.equals(otherPackageName)) {
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    if (currentActivity != null) {
      currentActivity.startActivity(intent);
    } else {
      getReactApplicationContext().startActivity(intent);
    }

    promise.resolve(true);
  } catch (Exception e) {
    promise.reject(new JSApplicationIllegalArgumentException(
        "Could not open URL '" + url + "': " + e.getMessage()));
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:43,代码来源:IntentModule.java

示例14: isRunningForeground

import android.content.ComponentName; //导入方法依赖的package包/类
private boolean isRunningForeground(Context context)
{
    ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
    String currentPackageName = cn.getPackageName();
    if(!TextUtils.isEmpty(currentPackageName) && currentPackageName.equals(context.getPackageName()))
    {
        return true ;
    }

    return false ;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:13,代码来源:SecurityHandler.java

示例15: getParentActivityIntent

import android.content.ComponentName; //导入方法依赖的package包/类
public static Intent getParentActivityIntent(Context context, ComponentName componentName) throws NameNotFoundException {
    String parentActivity = getParentActivityName(context, componentName);
    if (parentActivity == null) {
        return null;
    }
    ComponentName target = new ComponentName(componentName.getPackageName(), parentActivity);
    return getParentActivityName(context, target) == null ? IntentCompat.makeMainActivity(target) : new Intent().setComponent(target);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:9,代码来源:NavUtils.java


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