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.android.leanlauncher.IconCache.java

private String findDrawableFromIconPack(String packageName, String className) {
    if (mIconPackDrawables == null || mIconPackDrawables.size() == 0) {
        return null;
    }/*from   w  ww  .  j a  v a2 s .com*/

    String drawableName = null;
    for (ComponentName key : mIconPackDrawables.keySet()) {
        if (key.getPackageName().equalsIgnoreCase(packageName)) {
            drawableName = mIconPackDrawables.get(key);
            if (!TextUtils.isEmpty(drawableName)) {
                Log.d(TAG, drawableName + " -- found for -- " + packageName);

                if (className == null || className.equalsIgnoreCase(key.getClassName())) {
                    // we've found it
                    break;
                }
            }
        }
    }

    return drawableName;
}

From source file:com.facebook.AppEventsLogger.java

/**
 * Source Application setters and getters
 *///from ww w .j  av  a 2  s .co  m
private static void setSourceApplication(Activity activity) {

    ComponentName callingApplication = activity.getCallingActivity();
    if (callingApplication != null) {
        String callingApplicationPackage = callingApplication.getPackageName();
        if (callingApplicationPackage.equals(activity.getPackageName())) {
            // open by own app.
            resetSourceApplication();
            return;
        }
        sourceApplication = callingApplicationPackage;
    }

    // Tap icon to open an app will still get the old intent if the activity was opened by an intent before.
    // Introduce an extra field in the intent to force clear the sourceApplication.
    Intent openIntent = activity.getIntent();
    if (openIntent == null
            || openIntent.getBooleanExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, false)) {
        resetSourceApplication();
        return;
    }

    Bundle applinkData = AppLinks.getAppLinkData(openIntent);

    if (applinkData == null) {
        resetSourceApplication();
        return;
    }

    isOpenedByApplink = true;

    Bundle applinkReferrerData = applinkData.getBundle("referer_app_link");

    if (applinkReferrerData == null) {
        sourceApplication = null;
        return;
    }

    String applinkReferrerPackage = applinkReferrerData.getString("package");
    sourceApplication = applinkReferrerPackage;

    // Mark this intent has been used to avoid use this intent again and again.
    openIntent.putExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, true);

    return;
}

From source file:com.facebook.appevents.AppEventsLogger.java

/**
 * Source Application setters and getters
 *//*  w  w  w  .j a  v  a 2 s  . c o m*/
private static void setSourceApplication(Activity activity) {

    ComponentName callingApplication = activity.getCallingActivity();
    if (callingApplication != null) {
        String callingApplicationPackage = callingApplication.getPackageName();
        if (callingApplicationPackage.equals(activity.getPackageName())) {
            // open by own app.
            resetSourceApplication();
            return;
        }
        sourceApplication = callingApplicationPackage;
    }

    // Tap icon to open an app will still get the old intent if the activity was opened by an
    // intent before. Introduce an extra field in the intent to force clear the
    // sourceApplication.
    Intent openIntent = activity.getIntent();
    if (openIntent == null
            || openIntent.getBooleanExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, false)) {
        resetSourceApplication();
        return;
    }

    Bundle applinkData = AppLinks.getAppLinkData(openIntent);

    if (applinkData == null) {
        resetSourceApplication();
        return;
    }

    isOpenedByApplink = true;

    Bundle applinkReferrerData = applinkData.getBundle("referer_app_link");

    if (applinkReferrerData == null) {
        sourceApplication = null;
        return;
    }

    String applinkReferrerPackage = applinkReferrerData.getString("package");
    sourceApplication = applinkReferrerPackage;

    // Mark this intent has been used to avoid use this intent again and again.
    openIntent.putExtra(SOURCE_APPLICATION_HAS_BEEN_SET_BY_THIS_INTENT, true);

    return;
}

From source file:com.android.leanlauncher.IconCache.java

public synchronized Bitmap getIconForComponent(ComponentName componentName, UserHandleCompat user) {
    if (componentName == null || TextUtils.isEmpty(componentName.getPackageName())) {
        // happens on first load sometimes
        return null;
    }/*from  ww  w .  j a  v  a2 s .  c  o m*/
    CacheEntry entry = getEntryForPackage(componentName.getPackageName(), user);
    return entry.icon;
}

From source file:com.launcher.silverfish.HomeScreenFragment.java

private void loadWidget() {
    ComponentName cn = sqlHelper.getWidgetContentName();

    Log.d("Widget creation", "Loaded from db: " + cn.getClassName() + " - " + cn.getPackageName());
    // Check that there actually is a widget in the database
    if (cn.getPackageName().isEmpty() && cn.getClassName().isEmpty()) {
        Log.d("Widget creation", "DB was empty");
        return;/*from  w  w w .  ja  v  a2  s.c o m*/
    }
    Log.d("Widget creation", "DB was not empty");

    final List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders();

    // Get AppWidgetProviderInfo
    AppWidgetProviderInfo appWidgetInfo = null;
    // Just in case you want to see all package and class names of installed widget providers,
    // this code is useful
    for (final AppWidgetProviderInfo info : infos) {
        Log.d("AD3", info.provider.getPackageName() + " / " + info.provider.getClassName());
    }
    // Iterate through all infos, trying to find the desired one
    for (final AppWidgetProviderInfo info : infos) {
        if (info.provider.getClassName().equals(cn.getClassName())
                && info.provider.getPackageName().equals(cn.getPackageName())) {
            // We found it!
            appWidgetInfo = info;
            break;
        }
    }
    if (appWidgetInfo == null) {
        Log.d("Widget creation", "app info was null");
        return; // Stop here
    }

    // Allocate the hosted widget id
    int appWidgetId = mAppWidgetHost.allocateAppWidgetId();

    boolean allowed_to_bind = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn);

    // Ask the user to allow this app to have access to their widgets
    if (!allowed_to_bind) {
        Log.d("Widget creation", "asking for permission");
        Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
        Bundle args = new Bundle();
        args.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, cn);
        if (Build.VERSION.SDK_INT >= 21) {
            args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE, null);
        }
        i.putExtras(args);
        startActivityForResult(i, REQUEST_BIND_APPWIDGET);
        return;
    } else {

        Log.d("Widget creation", "Allowed to bind");
        Log.d("Widget creation", "creating widget");
        //Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
        //createWidgetFromId(appWidgetId);
    }
    // Create the host view
    AppWidgetHostView hostView = mAppWidgetHost.createView(getActivity().getBaseContext(), appWidgetId,
            appWidgetInfo);

    // Set the desired widget
    hostView.setAppWidget(appWidgetId, appWidgetInfo);

    placeWidget(hostView);
}

From source file:at.vcity.androidimsocket.services.IMService.java

public boolean isForeground(String myPackage) {
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> runningTaskInfo = manager.getRunningTasks(1);
    ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
    return componentInfo.getPackageName().equals(myPackage);
}

From source file:com.launcher.silverfish.launcher.homescreen.HomeScreenFragment.java

private void loadWidget() {
    ComponentName cn = settings.getWidget();

    Log.d("Widget creation", "Loaded from db: " + cn.getClassName() + " - " + cn.getPackageName());
    // Check that there actually is a widget in the database
    if (cn.getPackageName().isEmpty() && cn.getClassName().isEmpty()) {
        Log.d("Widget creation", "DB was empty");
        return;//w w  w .jav  a  2 s .co m
    }
    Log.d("Widget creation", "DB was not empty");

    final List<AppWidgetProviderInfo> infos = mAppWidgetManager.getInstalledProviders();

    // Get AppWidgetProviderInfo
    AppWidgetProviderInfo appWidgetInfo = null;
    // Just in case you want to see all package and class names of installed widget providers,
    // this code is useful
    for (final AppWidgetProviderInfo info : infos) {
        Log.d("AD3", info.provider.getPackageName() + " / " + info.provider.getClassName());
    }
    // Iterate through all infos, trying to find the desired one
    for (final AppWidgetProviderInfo info : infos) {
        if (info.provider.getClassName().equals(cn.getClassName())
                && info.provider.getPackageName().equals(cn.getPackageName())) {
            // We found it!
            appWidgetInfo = info;
            break;
        }
    }
    if (appWidgetInfo == null) {
        Log.d("Widget creation", "app info was null");
        return; // Stop here
    }

    // Allocate the hosted widget id
    int appWidgetId = mAppWidgetHost.allocateAppWidgetId();

    boolean allowed_to_bind = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, cn);

    // Ask the user to allow this app to have access to their widgets
    if (!allowed_to_bind) {
        Log.d("Widget creation", "asking for permission");
        Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
        Bundle args = new Bundle();
        args.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, cn);
        if (Build.VERSION.SDK_INT >= 21) {
            args.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE, null);
        }
        i.putExtras(args);
        startActivityForResult(i, REQUEST_BIND_APPWIDGET);
        return;
    } else {

        Log.d("Widget creation", "Allowed to bind");
        Log.d("Widget creation", "creating widget");
        //Intent i = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
        //createWidgetFromId(appWidgetId);
    }
    // Create the host view
    AppWidgetHostView hostView = mAppWidgetHost.createView(getActivity().getBaseContext(), appWidgetId,
            appWidgetInfo);

    // Set the desired widget
    hostView.setAppWidget(appWidgetId, appWidgetInfo);

    placeWidget(hostView);
}

From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.menu_run_intent:
        runIntent();//  w w  w  .  j  ava 2 s  . c o  m
        return true;
    case R.id.set_editor_result:
        updateIntent();
        setResult(0, new Intent().putExtra(Editor.EXTRA_VALUE, mEditedIntent));
        finish();
        return true;
    case R.id.attach_intent_filter: {
        // We have specified component, just find IntentFilters for it
        final ComponentName componentName = mEditedIntent.getComponent();
        ExtendedPackageInfo.getExtendedPackageInfo(this, componentName.getPackageName(),
                new ExtendedPackageInfo.Callback() {
                    @Override
                    public void onPackageInfoAvailable(ExtendedPackageInfo extendedPackageInfo) {
                        try {
                            setAttachedIntentFilters(extendedPackageInfo
                                    .getComponentInfo(componentName.getClassName()).intentFilters);
                            Toast.makeText(IntentEditorActivity.this, R.string.intent_filter_attached,
                                    Toast.LENGTH_SHORT).show();
                        } catch (NullPointerException e) {
                            Toast.makeText(IntentEditorActivity.this, R.string.no_intent_filters_found,
                                    Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }

        return true;
    case R.id.detach_intent_filter:
        clearAttachedIntentFilters();
        return true;
    case R.id.component_info: {
        ComponentName component = mEditedIntent.getComponent();
        startActivity(new Intent(this, SingleFragmentActivity.class)
                .putExtra(SingleFragmentActivity.EXTRA_FRAGMENT, ComponentInfoFragment.class.getName())
                .putExtra(ComponentInfoFragment.ARG_PACKAGE_NAME, component.getPackageName())
                .putExtra(ComponentInfoFragment.ARG_COMPONENT_NAME, component.getClassName())
                .putExtra(ComponentInfoFragment.ARG_LAUNCHED_FROM_INTENT_EDITOR, true));
    }
        return true;
    case R.id.save: {
        updateIntent();
        SavedItemsDatabase.getInstance(this).saveIntent(this, mEditedIntent, mComponentType, mMethodId);
    }
        return true;
    case R.id.track_intent: {
        if (!item.isChecked()) {
            XIntentsLab xIntentsLab = XIntentsLabStatic.getInstance();
            if (xIntentsLab.havePermission()) {
                createIntentTracker();
            } else {
                try {
                    startIntentSenderForResult(
                            xIntentsLab.getRequestPermissionIntent(getPackageName()).getIntentSender(),
                            REQUEST_CODE_REQUEST_INTENT_TRACKER_PERMISSION, null, 0, 0, 0);
                } catch (IntentSender.SendIntentException e) {
                    e.printStackTrace();
                    // TODO: can we handle this?
                }
            }
        } else {
            removeIntentTracker();
        }
        return true;
    }
    case R.id.disable_interception:
        getPackageManager().setComponentEnabledSetting(
                new ComponentName(this, IntentEditorInterceptedActivity.class),
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
        Toast.makeText(this, R.string.interception_disabled, Toast.LENGTH_SHORT).show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.air.mobilebrowser.BrowserActivity.java

@Override
public void onPause() {
    ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(1);
    ComponentName topActivity = tasks.get(0).topActivity;
    String packageName = topActivity.getPackageName();

    if (!packageName.equals(super.getPackageName()) && !packageName.equals("android")) {
        mBeenBackgrounded = true;//  w  ww.java  2s . co m
        executeAIRMobileFunction(JSNTVCmds.NTV_ENTER_BACKGROUND, null);
    }
    mWebView.onPause();
    super.onPause();
}

From source file:edu.umich.flowfence.service.Sandbox.java

public TaintSet removeTaint(TaintSet taintsToRemove, Set<String> allowedPackages) {
    synchronized (mTaintLock) {
        synchronized (mSync) {
            checkConnected();/*from w ww  .  j a  v  a  2s . c o  m*/
        }

        TaintSet.Builder removedBuilder = new TaintSet.Builder();
        TaintSet.Builder newTaint = mTaintSet.asBuilder();
        for (ComponentName name : taintsToRemove.asMap().keySet()) {
            if (allowedPackages.contains(name.getPackageName()) && mTaintSet.isTaintedWith(name)) {
                removedBuilder.addTaint(name, mTaintSet.getTaintAmount(name));
                newTaint.removeTaint(name);
            }
        }

        TaintSet removedSet = removedBuilder.build();
        if (TaintSet.EMPTY.equals(removedSet)) {
            return TaintSet.EMPTY;
        }

        onBeforeTaintRemove.fire(this, removedSet);
        synchronized (mSync) {
            mTaintSet = newTaint.build();
        }
        if (localLOGD) {
            Log.d(TAG, "After clean, sandbox " + mID + " now tainted with " + mTaintSet);
        }
        onTaintRemoved.fire(this, removedSet);
        return removedSet;
    }
}