Java Code Examples for android.content.ComponentName.getPackageName()

The following are Jave code examples for showing how to use getPackageName() of the android.content.ComponentName class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: lineagex86   File: SoundSettings.java   Source Code and License Vote up 6 votes
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();
}
 
Example 2
Project: TPlayer   File: MethodProxies.java   Source Code and License Vote up 6 votes
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;
}
 
Example 3
Project: LaunchEnr   File: SearchWidgetProvider.java   Source Code and License Vote up 6 votes
/**
 * -     * 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;
}
 
Example 4
Project: OpenYOLO-Android   File: HintPickerActivity.java   Source Code and License Vote up 6 votes
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;
}
 
Example 5
Project: OpenYOLO-Android   File: SaveCredentialActivity.java   Source Code and License Vote up 6 votes
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;
}
 
Example 6
Project: LaunchTime   File: DB.java   Source Code and License Vote up 6 votes
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;
    }
 
Example 7
Project: container   File: VJobSchedulerService.java   Source Code and License Vote up 6 votes
@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);
}
 
Example 8
Project: Accessibility   File: InstallAccessibility.java   Source Code and License Vote up 5 votes
@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);
}
 
Example 9
Project: android-project-gallery   File: CrashHandler.java   Source Code and License Vote up 5 votes
/**
 * 重新启动
 */
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;
		}
	}
}
 
Example 10
Project: TPlayer   File: BroadcastBadger2.java   Source Code and License Vote up 5 votes
@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;
}
 
Example 11
Project: Nird2   File: PanicPreferencesFragment.java   Source Code and License Vote up 5 votes
@Nullable
private String getCallingPackageName() {
	ComponentName componentName = getActivity().getCallingActivity();
	String packageName = null;
	if (componentName != null) {
		packageName = componentName.getPackageName();
	}
	return packageName;
}
 
Example 12
Project: Nird2   File: PanicPreferencesFragment.java   Source Code and License Vote up 5 votes
@Nullable
private String getCallingPackageName() {
	ComponentName componentName = getActivity().getCallingActivity();
	String packageName = null;
	if (componentName != null) {
		packageName = componentName.getPackageName();
	}
	return packageName;
}
 
Example 13
Project: ViewDebugHelper   File: ActivityHelper.java   Source Code and License Vote up 5 votes
/**
 * 慎重使用此函数<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 "";
}
 
Example 14
Project: RNLearn_Project1   File: IntentModule.java   Source Code and License Vote up 5 votes
/**
 * 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()));
  }
}
 
Example 15
Project: atlas   File: SecurityHandler.java   Source Code and License Vote up 5 votes
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 ;
}
 
Example 16
Project: letv   File: NavUtils.java   Source Code and License Vote up 5 votes
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);
}
 
Example 17
Project: DroidPlugin   File: LaunchModeTestActivity.java   Source Code and License Vote up 5 votes
private String toComponentName(ComponentName cn) {
    if (cn == null) {
        return null;
    } else {
        return cn.getPackageName() + "/" + cn.getShortClassName();
    }
}
 
Example 18
Project: simple-share-android   File: PackageManagerUtils.java   Source Code and License Vote up 5 votes
public static ComponentName getComponentName(Context context, Intent intent) {
	PackageManager packageManager = context.getPackageManager();
	ComponentName resolvedComponentName = intent.resolveActivity(packageManager);
	try {
		ActivityInfo activityInfo = packageManager.getActivityInfo(resolvedComponentName, 0);
		if (activityInfo.targetActivity != null) {
			return new ComponentName(resolvedComponentName.getPackageName(), activityInfo.targetActivity);
		}
	} catch (PackageManager.NameNotFoundException e) {
		// TODO nothing
	}
	return resolvedComponentName;
}
 
Example 19
Project: LaunchTime   File: FeedbackActivity.java   Source Code and License Vote up 4 votes
private String makeCompname(ComponentName componentName) {
    return componentName.getPackageName() + "/" + componentName.getClassName();
}
 
Example 20
Project: FlickLauncher   File: PredictiveAppsProvider.java   Source Code and License Vote up 4 votes
private String buildComponentString(ComponentName component) {
    return component.getPackageName() + " " + component.getClassName();
}