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.nbplus.vbroadlauncher.HomeLauncherActivity.java

/**
@Override//from  w  ww  .  ja v  a  2  s.  com
protected void onNewIntent(Intent intent) {
//super.onNewIntent(intent);
if (intent == null) {
    return;
}
        
String action = intent.getAction();
Log.d(TAG, "onNewIntent.. action = " + action);
//        if (PushConstants.ACTION_PUSH_STATUS_CHANGED.equals(action) || PushConstants.ACTION_PUSH_MESSAGE_RECEIVED.equals(action)) {
//            setPushServiceStatus(intent.getIntExtra(PushConstants.EXTRA_PUSH_STATUS_VALUE, PushConstants.PUSH_STATUS_VALUE_DISCONNECTED));
//
//            if (mActivityInteractionListener != null) {
//                for (OnActivityInteractionListener listener : mActivityInteractionListener) {
//                    listener.onPushReceived(intent);
//                }
//            }
//        }
}
*/

protected boolean isMyLauncherDefault() {
    final IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
    filter.addCategory(Intent.CATEGORY_HOME);

    List<IntentFilter> filters = new ArrayList<IntentFilter>();
    filters.add(filter);

    final String myPackageName = getPackageName();
    List<ComponentName> activities = new ArrayList<ComponentName>();
    final PackageManager packageManager = (PackageManager) getPackageManager();

    // You can use name of your package here as third argument
    packageManager.getPreferredActivities(filters, activities, null);

    for (ComponentName activity : activities) {
        if (myPackageName.equals(activity.getPackageName())) {
            return true;
        }
    }
    return false;
}

From source file:ee.ioc.phon.android.speak.RecognizerIntentActivity.java

/**
 * <p>Only for developers, i.e. we are not going to localize these strings.</p>
 */// ww  w  .  java 2s .c om
private String[] getDetails() {
    String callingActivityClassName = null;
    String callingActivityPackageName = null;
    String pendingIntentTargetPackage = null;
    ComponentName callingActivity = getCallingActivity();
    if (callingActivity != null) {
        callingActivityClassName = callingActivity.getClassName();
        callingActivityPackageName = callingActivity.getPackageName();
    }
    if (mExtraResultsPendingIntent != null) {
        pendingIntentTargetPackage = mExtraResultsPendingIntent.getTargetPackage();
    }
    List<String> info = new ArrayList<String>();
    info.add("ID: " + Utils.getUniqueId(PreferenceManager.getDefaultSharedPreferences(this)));
    info.add("User-Agent comment: " + mRecSessionBuilder.getUserAgentComment());
    info.add("Calling activity class name: " + callingActivityClassName);
    info.add("Calling activity package name: " + callingActivityPackageName);
    info.add("Pending intent target package: " + pendingIntentTargetPackage);
    info.add("Selected grammar: " + mRecSessionBuilder.getGrammarUrl());
    info.add("Selected target lang: " + mRecSessionBuilder.getGrammarTargetLang());
    info.add("Selected server: " + mRecSessionBuilder.getServerUrl());
    info.add("Intent action: " + getIntent().getAction());
    info.addAll(Utils.ppBundle(mExtras));
    return info.toArray(new String[info.size()]);
}

From source file:lewa.support.v7.app.ActionBarActivityDelegateBase.java

public boolean isHome() {
    if (!IS_IGNORE_HOME) {
        try {//from  ww w  .  j a  v a 2  s. c  o  m

            ActivityManager mActivityManager = (ActivityManager) mActivity
                    .getSystemService(Context.ACTIVITY_SERVICE);
            if (mActivityManager != null) {
                List<RunningTaskInfo> rti = mActivityManager.getRunningTasks(1);
                // boolean isLauncherClass =
                // rti.get(0).topActivity.getClassName()
                // .equals("com.lewa.launcher.Launcher");
                // Log.i(TAG,"isLauncherClass :"+rti.get(0).topActivity.getClassName());
                if (rti != null) {
                    if (rti.size() != 0) {
                        ComponentName cn = rti.get(0).topActivity;
                        if (cn != null) {
                            return getHomes().contains(cn.getPackageName());
                        }

                    }
                }

            }

        } catch (Exception e) {

        }
    }

    //
    return false;
}

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

private static ArrayList<ItemInfo> getItemsByPackageName(final String pn, final UserHandleCompat user) {
    ItemInfoFilter filter = new ItemInfoFilter() {
        @Override/*w  ww. ja  va 2  s .  c o  m*/
        public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
            return cn.getPackageName().equals(pn) && info.user.equals(user);
        }
    };
    return filterItemInfos(sBgItemsIdMap.values(), filter);
}

From source file:android.support.v7.widget.SuggestionsAdapter.java

/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set./*  w  w w  .ja va 2  s .  c om*/
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0)
        return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
        return null;
    }
    return drawable;
}

From source file:com.paywith.ibeacon.service.IBeaconService.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;
    if (componentInfo.getPackageName().equals(myPackage)) {
        return true;
    }/*  ww  w  .  j a v a 2 s  .c  o m*/
    return false;
}

From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java

public String getAppName() {
    String packagename;//from   w ww .  j  a v a  2 s .c om

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {

        KeyguardManager myKM = (KeyguardManager) getApplicationContext()
                .getSystemService(Context.KEYGUARD_SERVICE);
        if (myKM.inKeyguardRestrictedInputMode()) {
            //it is locked

            System.out.println("[AppLogger]Screen is locked");
            packagename = "LockScreen";
        } else {
            //it is not locked

            ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE);

            List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
            ComponentName componentInfo = taskInfo.get(0).topActivity;

            packagename = componentInfo.getPackageName();

            System.out.println(
                    "[AppLogger]Build Version:" + Build.VERSION.SDK_INT + ",Package Name:" + packagename);
        }
    }

    else {

        KeyguardManager myKM = (KeyguardManager) getApplicationContext()
                .getSystemService(Context.KEYGUARD_SERVICE);
        if (myKM.inKeyguardRestrictedInputMode()) {
            //it is locked

            System.out.println("[AppLogger]Screen is locked");
            packagename = "LockScreen";
        }

        else {

            //ActivityManager am =(ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
            //packagename = am.getRunningAppProcesses().get(0).processName;

            packagename = getTopPackage();
        }

        System.out.println(
                "[AlarmReceiver]Build Version:" + Build.VERSION.SDK_INT + "Package Name:" + packagename);
    }
    return packagename;
}

From source file:net.lp.actionbarpoirot.helpers.DualTaskStackBuilder.java

/**
 * Add the activity parent chain as specified by manifest &lt;meta-data&gt;
 * elements to the task stack builder./*from   www. j  a v  a  2  s.  c  o  m*/
 * 
 * @param sourceActivityName
 *            Must specify an Activity component. All parents of this
 *            activity will be added
 * @return This DualTaskStackBuilder for method chaining
 */
public DualTaskStackBuilder addParentStack(ComponentName sourceActivityName) {
    final int insertAt = mIntents.size();
    try {
        Intent parent = DualNavUtils.getParentActivityIntent(mSourceContext, sourceActivityName);
        while (parent != null) {
            mIntents.add(insertAt, parent);
            parent = DualNavUtils.getParentActivityIntent(mSourceContext, parent.getComponent());
        }
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Bad ComponentName while traversing activity parent metadata");
        // ***ActionBarPoirot
        // added*******************************************************************************************************************
        if (PoirotWindow.DEBUG)
            e.printStackTrace();
        // If this runs in the extension app, then some parent search is
        // going to throw an error eventually. By then the right intent has
        // been added.
        final String mainPackageName = ((ActivityHelperUser) mSourceContext).getHomePackageName();
        if (!mainPackageName.equalsIgnoreCase(sourceActivityName.getPackageName())
                && sourceActivityName.getPackageName().startsWith(mainPackageName)) {
            // do nothing
        } else {
            throw new IllegalArgumentException(e);
        }
    }
    return this;
}

From source file:csh.cryptonite.Cryptonite.java

public void launchTerm(boolean root) {
    /* Is a reminal emulator running? */

    /* If Terminal Emulator is not installed or outdated,
     * offer to download/*from  w  w  w .j av  a 2  s  .c  o m*/
     */
    if (hasExtterm(getBaseContext()) != TERM_AVAILABLE) {
        TermUnavailableDialogFragment newFragment = TermUnavailableDialogFragment.newInstance();
        newFragment.show(getSupportFragmentManager(), "dialog");
    } else {
        ComponentName termComp = new ComponentName("jackpal.androidterm", "jackpal.androidterm.Term");
        try {
            PackageInfo pinfo = getBaseContext().getPackageManager().getPackageInfo(termComp.getPackageName(),
                    0);
            String patchVersion = pinfo.versionName;
            Log.v(TAG, "Terminal Emulator version: " + patchVersion);
            int patchCode = pinfo.versionCode;

            if (patchCode < 32) {
                showAlert(R.string.error, R.string.app_terminal_outdated);
            } else if (patchCode < 43) {
                Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.setComponent(termComp);
                runTerm(intent, extTermRunning(), root);
            } else {
                ComponentName remoteComp = new ComponentName("jackpal.androidterm",
                        "jackpal.androidterm.RemoteInterface");
                Intent intent = new Intent("jackpal.androidterm.RUN_SCRIPT");
                intent.setComponent(remoteComp);
                runTerm(intent, false, root);
            }

        } catch (PackageManager.NameNotFoundException e) {
            Toast.makeText(Cryptonite.this, R.string.app_terminal_missing, Toast.LENGTH_LONG).show();
        }
    }
}

From source file:com.android.launcher3.Folder.java

public void onDropCompleted(final View target, final DragObject d, final boolean isFlingToDelete,
        final boolean success) {
    if (mDeferDropAfterUninstall) {
        Log.d(TAG, "Deferred handling drop because waiting for uninstall.");
        mDeferredAction = new Runnable() {
            public void run() {
                onDropCompleted(target, d, isFlingToDelete, success);
                mDeferredAction = null;/*from  ww w . ja  v  a  2 s  .c o  m*/
            }
        };
        return;
    }

    boolean beingCalledAfterUninstall = mDeferredAction != null;
    boolean successfulDrop = success && (!beingCalledAfterUninstall || mUninstallSuccessful);

    if (successfulDrop) {
        if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target != this) {
            replaceFolderWithFinalItem();
        }
    } else {
        setupContentForNumItems(getItemCount());

        /* SPRD: bug388051 2014-12-31 Bugfix view still exist when application is removed {@ */
        // The drag failed, we need to return the item to the folder
        List<LauncherActivityInfoCompat> activityList = null;
        LauncherActivityInfoCompat resolveActivity = null;
        ComponentName componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent();
        LauncherAppsCompat appsCompat = LauncherAppsCompat.getInstance(getContext());
        UserHandleCompat userHandleCompat = UserHandleCompat.myUserHandle();
        if (componentName != null) {
            activityList = appsCompat.getActivityList(componentName.getPackageName(), userHandleCompat);
        } else {
            resolveActivity = appsCompat.resolveActivity(((ShortcutInfo) d.dragInfo).intent, userHandleCompat);
        }
        if ((activityList != null && activityList.size() > 0) || resolveActivity != null) {
            mFolderIcon.onDrop(d);
        } else {
            if (getItemCount() <= 1) {
                replaceFolderWithFinalItem();
            }
        }
        /* SPRD: bug388051 2014-12-31 Bugfix view still exist when application is removed @} */

    }

    if (target != this) {
        if (mOnExitAlarm.alarmPending()) {
            mOnExitAlarm.cancelAlarm();
            if (!successfulDrop) {
                mSuppressFolderDeletion = true;
            }
            completeDragExit();
        }
    }

    mDeleteFolderOnDropCompleted = false;
    mDragInProgress = false;
    mItemAddedBackToSelfViaIcon = false;
    mCurrentDragInfo = null;
    mCurrentDragView = null;
    mSuppressOnAdd = false;

    // Reordering may have occured, and we need to save the new item locations. We do this once
    // at the end to prevent unnecessary database operations.
    updateItemLocationsInDatabaseBatch();
}