Example usage for android.content ComponentName getPackageName

List of usage examples for android.content ComponentName getPackageName

Introduction

In this page you can find the example usage for android.content ComponentName getPackageName.

Prototype

public @NonNull String getPackageName() 

Source Link

Document

Return the package name of this component.

Usage

From source file:com.luongbui.andersenfestival.muzei.AndersenFestivalSource.java

@Override
protected void onSubscriberAdded(ComponentName subscriber) {
    super.onSubscriberAdded(subscriber);
    //android.util.Log.d("onSubscriberAdded()", "onSubscriberAdded()");
    // Add the subscriber, so we can grant permissions later.
    Set<String> subs = prefs.getStringSet(SUBS_KEY, new TreeSet<String>());
    subs.add(subscriber.getPackageName());
    saveSubsPrefs(subs);/* ww w  .j  a va  2 s .c  o m*/
}

From source file:arun.com.chromer.settings.Preferences.java

@Nullable
public String secondaryBrowserPackage() {
    final String flatString = secondaryBrowserComponent();
    if (flatString == null) {
        return null;
    }/*from  w w w. ja  v  a2s. c  o  m*/
    final ComponentName cN = ComponentName.unflattenFromString(flatString);
    if (cN == null)
        return null;
    return cN.getPackageName();
}

From source file:arun.com.chromer.settings.Preferences.java

@Nullable
public String favSharePackage() {
    final String flatString = favShareComponent();
    if (flatString == null) {
        return null;
    }/* w  w w . ja  v a 2s .  co  m*/
    final ComponentName cN = ComponentName.unflattenFromString(flatString);
    if (cN == null)
        return null;
    return cN.getPackageName();
}

From source file:androidx.media.SessionToken2.java

/**
 * Constructor for the token. You can only create token for session service or library service
 * to use by {@link MediaController2} or {@link MediaBrowser2}.
 *
 * @param context The context.//from   ww  w  . j a v a2 s .  c o m
 * @param serviceComponent The component name of the media browser service.
 * @param uid uid of the app.
 * @hide
 */
@RestrictTo(LIBRARY_GROUP)
public SessionToken2(@NonNull Context context, @NonNull ComponentName serviceComponent, int uid) {
    if (serviceComponent == null) {
        throw new IllegalArgumentException("serviceComponent shouldn't be null");
    }
    mComponentName = serviceComponent;
    mPackageName = serviceComponent.getPackageName();
    mServiceName = serviceComponent.getClassName();
    // Calculate uid if it's not specified.
    final PackageManager manager = context.getPackageManager();
    if (uid < 0) {
        try {
            uid = manager.getApplicationInfo(mPackageName, 0).uid;
        } catch (PackageManager.NameNotFoundException e) {
            throw new IllegalArgumentException("Cannot find package " + mPackageName);
        }
    }
    mUid = uid;

    // Infer id and type from package name and service name
    String id = getSessionIdFromService(manager, MediaLibraryService2.SERVICE_INTERFACE, serviceComponent);
    if (id != null) {
        mId = id;
        mType = TYPE_LIBRARY_SERVICE;
    } else {
        // retry with session service
        mId = getSessionIdFromService(manager, MediaSessionService2.SERVICE_INTERFACE, serviceComponent);
        mType = TYPE_SESSION_SERVICE;
    }
    if (mId == null) {
        throw new IllegalArgumentException("service " + mServiceName + " doesn't implement"
                + " session service nor library service. Use service's full name.");
    }
    mSessionCompatToken = null;
}

From source file:com.cognizant.glass.bluetoothconnect.DemoAppRecieverService.java

/**
 * @param packageName/*www . j  a v  a2  s. c  o  m*/
 * @return checks if a particular application is in the foreground
 */
public boolean isForeground(final String packageName) {
    // Get the Activity Manager
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

    // Get a list of running tasks, we are only interested in the last one,
    // the top most so we give a 1 as parameter so we only get the topmost.
    final List<ActivityManager.RunningTaskInfo> task = manager.getRunningTasks(1);

    // Get the info we need for comparison.
    final ComponentName componentInfo = task.get(0).topActivity;

    // Check if it matches our package name.
    if (componentInfo.getPackageName().equals(packageName)
            && componentInfo.getClassName().contains("SecondActivity"))
        return true;

    // If not then our app is not on the foreground.
    return false;
}

From source file:ca.mimic.apphangar.Settings.java

protected static void resetIconComponent(ComponentName componentName) {
    Tools.HangarLog("resetIconCache!: " + componentName.getPackageName());

    try {//from ww w .  j a  va  2  s. c  o  m
        Intent intent = mContext.getPackageManager().getLaunchIntentForPackage(componentName.getPackageName());
        ResolveInfo rInfo = mContext.getPackageManager().resolveActivity(intent, 0);

        Drawable icon = new IconCacheHelper(mContext).getFullResIcon(rInfo.activityInfo, true);
        Bitmap bitmap = Tools.drawableToBitmap(icon);
        IconCacheHelper.preloadComponent(mContext, componentName, bitmap,
                Tools.dpToPx(mContext, CACHED_ICON_SIZE));
        myService.execute(SERVICE_CREATE_NOTIFICATIONS);
        mAppRowAdapter.reDraw(true);
        updateRowItem();
    } catch (Exception e) {
        Tools.HangarLog("reset Icon Cache exception: " + e);
    }
}

From source file:com.tasomaniac.openwith.resolver.ResolverActivity.java

@SuppressWarnings("deprecation")
private String getCallerPackagerLegacy() {
    String callerPackage;//from  w w w  . j a  v  a  2s  . com
    ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    final List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(1);
    final ComponentName topActivity = runningTasks.get(0).baseActivity;
    callerPackage = topActivity.getPackageName();
    return callerPackage;
}

From source file:org.ulteo.ovd.MainWindow.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from w  w  w.j a v  a  2  s. c o m
    context = this;

    TextView tvVersion = (TextView) findViewById(R.id.tvVersion);
    try {
        ComponentName comp = new ComponentName(this, getClass());
        PackageInfo pinfo = getPackageManager().getPackageInfo(comp.getPackageName(), 0);
        tvVersion.setText(Config.VERSION.replace("%", pinfo.versionName));
    } catch (android.content.pm.PackageManager.NameNotFoundException e) {
        tvVersion.setText(Config.VERSION.replace("%", ""));
    }
    tvVersion.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showWebsite();
        }
    });

    loginTxtField = (EditText) findViewById(R.id.login);
    passwdTxtField = (EditText) findViewById(R.id.password);
    sessionmTxtField = (EditText) findViewById(R.id.sessionm);
    tvNoNet = (TextView) findViewById(R.id.tvNoNet);

    imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);

    startBtn = (Button) findViewById(R.id.button_Start);
    startBtn.setOnClickListener(this);
}

From source file:edu.mit.mobile.android.demomode.DemoMode.java

@Override
public boolean onItemLongClick(AdapterView<?> adapter, View v, int position, long id) {
    switch (adapter.getId()) {
    case R.id.grid: {
        if (!mLocked) {
            getContentResolver().delete(ContentUris.withAppendedId(LauncherItem.CONTENT_URI, id), null, null);
            return true;
        }/* w  ww  .j  a v a  2  s .c  o m*/
    }
        break;

    case R.id.all_apps: {
        final ApplicationInfo appInfo = (ApplicationInfo) mAllApps.getItemAtPosition(position);
        final ContentValues cv = new ContentValues();
        final ComponentName c = appInfo.intent.getComponent();

        cv.put(LauncherItem.ACTIVITY_NAME, c.getClassName());
        cv.put(LauncherItem.PACKAGE_NAME, c.getPackageName());
        getContentResolver().insert(LauncherItem.CONTENT_URI, cv);
        mDrawer.close();
        return true;

    }
    }
    return false;
}

From source file:csh.cryptonite.Cryptonite.java

public static int hasExtterm(Context context) {
    ComponentName termComp = new ComponentName("jackpal.androidterm", "jackpal.androidterm.Term");
    try {//from w  w  w.j  av a  2s .c o  m
        PackageInfo pinfo = context.getPackageManager().getPackageInfo(termComp.getPackageName(), 0);
        int patchCode = pinfo.versionCode;

        if (patchCode < 32) {
            return TERM_OUTDATED;
        } else {
            return TERM_AVAILABLE;
        }
    } catch (PackageManager.NameNotFoundException e) {
        return TERM_UNAVAILABLE;
    }
}