Example usage for android.content Intent getComponent

List of usage examples for android.content Intent getComponent

Introduction

In this page you can find the example usage for android.content Intent getComponent.

Prototype

public @Nullable ComponentName getComponent() 

Source Link

Document

Retrieve the concrete component associated with the intent.

Usage

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

/**
 * Returns true if the intent is a valid launch intent for a launcher activity of an app.
 * This is used to identify shortcuts which are different from the ones exposed by the
 * applications' manifest file.//w w  w. jav a 2s  . co m
 *
 * @param launchIntent The intent that will be launched when the shortcut is clicked.
 */
public static boolean isLauncherAppTarget(Intent launchIntent) {
    if (launchIntent != null && Intent.ACTION_MAIN.equals(launchIntent.getAction())
            && launchIntent.getComponent() != null && launchIntent.getCategories() != null
            && launchIntent.getCategories().size() == 1 && launchIntent.hasCategory(Intent.CATEGORY_LAUNCHER)
            && TextUtils.isEmpty(launchIntent.getDataString())) {
        // An app target can either have no extra or have ItemInfo.EXTRA_PROFILE.
        Bundle extras = launchIntent.getExtras();
        if (extras == null) {
            return true;
        } else {
            Set<String> keys = extras.keySet();
            return keys.size() == 1 && keys.contains(ItemInfo.EXTRA_PROFILE);
        }
    }
    ;
    return false;
}

From source file:edu.mit.media.funf.probe.Probe.java

protected void onHandleIntent(Intent intent) {
    String action = intent.getAction();
    Log.d(TAG, getDisplayName() + ": " + action);
    Log.d(TAG, "Component: " + intent.getComponent() == null ? "<none>" : intent.getComponent().getClassName());

    getHistoryPrefs();//from  w w  w.  j  a  v  a 2s.  c  om
    if (requestsIntent == null) {
        loadRequestsIntent(intent);
        if (requestsIntent == null) {
            Log.d(TAG, "Did not successfully load requests Intent");
            return;
        }
    }

    updateRequests();

    Log.d(TAG, "RunIntent " + (requestsIntent == null ? "<null>" : "exists"));

    if (intent.getComponent().getClassName().equals(Probe.class.getName())) { // Internally queued, not available outside of probe class
        if (ACTION_RUN.equals(action) || ACTION_STOP.equals(action) || ACTION_DISABLE.equals(action)) {
            ProbeScheduler scheduler = getScheduler();
            ArrayList<Intent> requests = requestsIntent.getParcelableArrayListExtra(INTERNAL_REQUESTS_KEY);
            Log.d(TAG, "Requests:" + requests);
            if (isAvailableOnDevice() && !ACTION_DISABLE.equals(action)
                    && scheduler.shouldBeEnabled(this, requests)) {
                if (ACTION_RUN.equals(action)) {
                    _run();
                } else {
                    _stop();
                }
            } else {
                _disable();
                updateInternalRequestsPendingIntent();
            }

            Long nextScheduledTime = scheduler.scheduleNextRun(this, requests);
            Log.d(TAG, "Next scheduled time: " + nextScheduledTime);
            if (nextScheduledTime == null) {
                getHistoryPrefs().edit().remove(NEXT_RUN_TIME_KEY).commit();
            } else {
                getHistoryPrefs().edit().putLong(NEXT_RUN_TIME_KEY, nextScheduledTime).commit();
            }
        } else if (ACTION_INTERNAL_CALLBACK_REGISTERED.equals(action)) {
            Intent callbackRegisteredIntent = intent.getParcelableExtra(INTERNAL_CALLBACK_INTENT);
            PendingIntent callback = intent.getParcelableExtra(CALLBACK_KEY);
            _callback_registered(callbackRegisteredIntent, callback);
        }
    } else if (ACTION_REQUEST.equals(action) || action == null) {
        ArrayList<Bundle> test = Utils.getArrayList(intent.getExtras(), REQUESTS_KEY);
        Log.d(TAG, "REQUEST: " + test);
        boolean succesfullyQueued = queueRequest(intent);
        if (succesfullyQueued) {
            run();
        }
    } else if (ACTION_INTERNAL_REQUESTS.equals(action)) {

    } else if (ACTION_RUN.equals(action)) { // External stop, queue up stop
        run();
    } else if (ACTION_STOP.equals(action)) { // External stop, queue up stop
        stop();
    } else if (ACTION_DISABLE.equals(action)) { // External disable, queue up disable
        disable();
    } else if (ACTION_SEND_DETAILS.equals(action)) { // DOESN'T NEED requests
        PendingIntent callback = intent.getParcelableExtra(CALLBACK_KEY);
        sendProbeDetails(callback);
    } else if (ACTION_SEND_CONFIGURATION.equals(action)) {
        //PendingIntent callback = intent.getParcelableExtra(CALLBACK_KEY);
        //sendProbeConfiguration(callback);
    } else if (ACTION_SEND_STATUS.equals(action)) { // DOESN'T NEED requests
        PendingIntent callback = intent.getParcelableExtra(CALLBACK_KEY);
        sendProbeStatus(callback);
    } else {
        onHandleCustomIntent(intent);
    }
}

From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java

/**
 * Filter the intent to a single activity so a chooser won't pop up. If not found, it tries to
 * resolve intent by falling back to default category.
 * @param intent intent to filter./*  w  w w.  j a va2s  .  c  o m*/
 */
private void filterIntentWithCategory(final Intent intent) {
    /* Filter intent for the target package name */
    filterIntent(intent);

    /* If the intent could not be resolved */
    if (intent.getComponent() == null) {
        /* If there was no category */
        if (intent.getCategories() == null)

            /* Notification cannot be done */
            throw new ActivityNotFoundException();

        /* Remove categories */
        Collection<String> categories = new HashSet<String>(intent.getCategories());
        for (String category : categories)
            intent.removeCategory(category);

        /* Try filtering again */
        filterIntent(intent);

        /* Notification cannot be done, skip content */
        if (intent.getComponent() == null)
            throw new ActivityNotFoundException();
    }
}

From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java

/** Show content activity */
private void showContent(EngagementReachContent content) {
    /* Update state */
    mState = State.SHOWING;//from   w  ww. j  a va  2s . c  om
    mCurrentShownContentId = content.getLocalId();

    /* Start activity */
    Intent intent = content.getIntent();
    filterIntentWithCategory(intent);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY);
    mShowingActivity = intent.getComponent();
    mContext.startActivity(intent);
}

From source file:ti.modules.titanium.android.AndroidModule.java

@Kroll.method
public boolean isServiceRunning(IntentProxy intentProxy) {
    Intent intent = intentProxy.getIntent();
    if (intent == null) {
        Log.w(TAG, "isServiceRunning called with empty intent.  Will return false, but value is meaningless.");
        return false;
    }//  w  w w.  j a  va2  s .  c  o m

    TiApplication app = TiApplication.getInstance();
    if (app == null) {
        Log.w(TAG,
                "Application instance is no longer available. Unable to check isServiceRunning. Returning false though value is meaningless.");
        return false;
    }

    ActivityManager am = (ActivityManager) app.getApplicationContext()
            .getSystemService(Context.ACTIVITY_SERVICE);
    if (am != null) {
        List<RunningServiceInfo> services = am.getRunningServices(Integer.MAX_VALUE);
        for (RunningServiceInfo service : services) {
            if (service.service.equals(intent.getComponent())) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.partypoker.poker.engagement.reach.EngagementDefaultNotifier.java

@Override
public void executeNotifAnnouncementAction(EngagementNotifAnnouncement notifAnnouncement) {
    /* Launch action intent (view activity in its own task) */
    try {// www.jav  a2s. co  m
        Intent intent = Intent.parseUri(notifAnnouncement.getActionURL(), 0);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
    } catch (Exception e) {
        /*
         * Invalid/Missing Action URL: launch/resume application instead if system notification and no
         * session.
         */
        if (notifAnnouncement.isSystemNotification()
                && EngagementActivityManager.getInstance().getCurrentActivityAlias() == null) {
            PackageManager packageManager = mContext.getPackageManager();
            Intent intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
            if (intent != null) {
                /*
                 * Set package null is the magic enabling the same behavior than launching from Home
                 * Screen, e.g. perfect resume of the task. No idea why the setPackage messes the intent
                 * up...
                 */
                if (intent.getComponent() != null)
                    intent.setPackage(null);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
            }
        }
    }
}

From source file:com.ubikod.capptain.android.sdk.reach.CapptainDefaultNotifier.java

@Override
public void executeNotifAnnouncementAction(CapptainNotifAnnouncement notifAnnouncement) {
    /* Launch action intent (view activity in its own task) */
    try {/*from   www . j  a  v  a2  s . c om*/
        Intent intent = Intent.parseUri(notifAnnouncement.getActionURL(), 0);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
    } catch (Exception e) {
        /*
         * Invalid/Missing Action URL: launch/resume application instead if system notification and no
         * session.
         */
        if (notifAnnouncement.isSystemNotification()
                && CapptainActivityManager.getInstance().getCurrentActivityAlias() == null) {
            PackageManager packageManager = mContext.getPackageManager();
            Intent intent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
            if (intent != null) {
                /*
                 * Set package null is the magic enabling the same behavior than launching from Home
                 * Screen, e.g. perfect resume of the task. No idea why the setPackage messes the intent
                 * up...
                 */
                if (intent.getComponent() != null)
                    intent.setPackage(null);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                doExecuteNotifAnnouncementAction(notifAnnouncement, intent);
            }
        }
    }
}

From source file:ro.ciubex.keepscreenlock.MainApplication.java

/**
 * Method invoked by the shortcut broadcast.
 *
 * @param data Intent data from the shortcut broadcast.
 * @param type Type of the event, uninstall or install.
 *//*from   w w  w .j  a v  a2 s . c  o  m*/
public void updateScreenShortcutListener(Intent data, ScreenLockShortcutUpdateListener.TYPE type) {
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (intent != null && name != null && intent.getComponent() != null) {
        String cls = String.valueOf(intent.getComponent().getClassName());
        if (cls.indexOf("keepscreenlock") > 0) {
            updateScreenShortcutPref(type);
        }
    }
}

From source file:com.android.settings.applications.CanBeOnSdCardChecker.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setHasOptionsMenu(true);//from  www  . j ava2  s .  c om

    mApplicationsState = ApplicationsState.getInstance(getActivity().getApplication());
    Intent intent = getActivity().getIntent();
    String action = intent.getAction();
    int defaultListType = LIST_TYPE_DOWNLOADED;
    String className = getArguments() != null ? getArguments().getString("classname") : null;
    if (className == null) {
        className = intent.getComponent().getClassName();
    }
    if (className.equals(RunningServicesActivity.class.getName()) || className.endsWith(".RunningServices")) {
        defaultListType = LIST_TYPE_RUNNING;
    } else if (className.equals(StorageUseActivity.class.getName())
            || Intent.ACTION_MANAGE_PACKAGE_STORAGE.equals(action) || className.endsWith(".StorageUse")) {
        mSortOrder = SORT_ORDER_SIZE;
        defaultListType = LIST_TYPE_ALL;
    } else if (Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS.equals(action)) {
        // Select the all-apps list, with the default sorting
        defaultListType = LIST_TYPE_ALL;
    }

    if (savedInstanceState != null) {
        mSortOrder = savedInstanceState.getInt(EXTRA_SORT_ORDER, mSortOrder);
        int tmp = savedInstanceState.getInt(EXTRA_DEFAULT_LIST_TYPE, -1);
        if (tmp != -1)
            defaultListType = tmp;
        mShowBackground = savedInstanceState.getBoolean(EXTRA_SHOW_BACKGROUND, false);
    }

    mDefaultListType = defaultListType;

    final Intent containerIntent = new Intent().setComponent(StorageMeasurement.DEFAULT_CONTAINER_COMPONENT);
    getActivity().bindService(containerIntent, mContainerConnection, Context.BIND_AUTO_CREATE);

    mInvalidSizeStr = getActivity().getText(R.string.invalid_size_value);
    mComputingSizeStr = getActivity().getText(R.string.computing_size);

    TabInfo tab = new TabInfo(this, mApplicationsState,
            getActivity().getString(R.string.filter_apps_third_party), LIST_TYPE_DOWNLOADED, this,
            savedInstanceState);
    mTabs.add(tab);

    if (!Environment.isExternalStorageEmulated()) {
        tab = new TabInfo(this, mApplicationsState, getActivity().getString(R.string.filter_apps_onsdcard),
                LIST_TYPE_SDCARD, this, savedInstanceState);
        mTabs.add(tab);
    }

    tab = new TabInfo(this, mApplicationsState, getActivity().getString(R.string.filter_apps_running),
            LIST_TYPE_RUNNING, this, savedInstanceState);
    mTabs.add(tab);

    tab = new TabInfo(this, mApplicationsState, getActivity().getString(R.string.filter_apps_all),
            LIST_TYPE_ALL, this, savedInstanceState);
    mTabs.add(tab);

    tab = new TabInfo(this, mApplicationsState, getActivity().getString(R.string.filter_apps_disabled),
            LIST_TYPE_DISABLED, this, savedInstanceState);
    mTabs.add(tab);

    mNumTabs = mTabs.size();
}

From source file:RhodesService.java

@Override
public void startActivity(Intent intent) {

    RhodesActivity ra = RhodesActivity.getInstance();
    if (intent.getComponent() != null
            && intent.getComponent().compareTo(new ComponentName(this, RhodesActivity.class.getName())) == 0) {
        Logger.T(TAG, "Start or bring main activity: " + RhodesActivity.class.getName() + ".");
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (ra == null) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            super.startActivity(intent);
            return;
        }//w  w w.  j av  a  2s.  co m
    }

    if (ra != null) {
        Logger.T(TAG, "Starting new activity on top.");
        if (DEBUG) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                for (String key : extras.keySet()) {
                    Object val = extras.get(key);
                    if (val != null)
                        Log.d(TAG, key + ": " + val.toString());
                    else
                        Log.d(TAG, key + ": <empty>");
                }
            }
        }
        ra.startActivity(intent);
    } else {
        throw new IllegalStateException(
                "Trying to start activity, but there is no main activity instance (we are in background, no UI active)");
    }
}