Example usage for android.content Intent setComponent

List of usage examples for android.content Intent setComponent

Introduction

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

Prototype

public @NonNull Intent setComponent(@Nullable ComponentName component) 

Source Link

Document

(Usually optional) Explicitly set the component to handle the intent.

Usage

From source file:org.videolan.myvlc.core.mediaController.AudioService.java

/**
 * Set up the remote control and tell the system we want to be the default receiver for the MEDIA buttons
 * @see http://android-developers.blogspot.fr/2010/06/allowing-applications-to-play-nicer.html
 *///from   www.j a v a  2 s .  c o m
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void setUpRemoteControlClient() {
    Context context = MyVLCApp.getAppContext();
    AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);

    if (Util.isICSOrLater()) {
        audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);

        if (mRemoteControlClient == null) {
            Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
            mediaButtonIntent.setComponent(mRemoteControlClientReceiverComponent);
            PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context, 0, mediaButtonIntent, 0);

            // create and register the remote control client
            mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
            audioManager.registerRemoteControlClient(mRemoteControlClient);
        }

        mRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
                | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
    } else if (Util.isFroyoOrLater()) {
        audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
    }
}

From source file:com.irccloud.android.data.collection.NotificationsList.java

private void showOtherNotifications() {
    String title = "";
    String text = "";
    String ticker;//from  ww w.  j  a va  2 s. co m
    NotificationCompat.Action action = null;
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext());
    final List<Notification> notifications = getOtherNotifications();

    int notify_type = Integer.parseInt(prefs.getString("notify_type", "1"));
    boolean notify = false;
    if (notify_type == 1 || (notify_type == 2 && NetworkConnection.getInstance().isVisible()))
        notify = true;

    if (notifications.size() > 0 && notify) {
        for (Notification n : notifications) {
            if (!n.shown) {
                Crashlytics.log(Log.DEBUG, "IRCCloud", "Posting notification for type " + n.message_type);
                if (n.message_type.equals("callerid")) {
                    title = n.network;
                    text = n.nick + " is trying to contact you";
                    ticker = n.nick + " is trying to contact you on " + n.network;

                    Intent i = new Intent(RemoteInputService.ACTION_REPLY);
                    i.setComponent(new ComponentName(
                            IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
                            RemoteInputService.class.getName()));
                    i.putExtra("cid", n.cid);
                    i.putExtra("eid", n.eid);
                    i.putExtra("chan", n.chan);
                    i.putExtra("buffer_type", n.buffer_type);
                    i.putExtra("network", n.network);
                    i.putExtra("to", n.nick);
                    i.putExtra("reply", "/accept " + n.nick);
                    action = new NotificationCompat.Action(R.drawable.ic_wearable_add, "Accept",
                            PendingIntent.getService(IRCCloudApplication.getInstance().getApplicationContext(),
                                    (int) (n.eid / 1000), i, PendingIntent.FLAG_UPDATE_CURRENT));
                } else if (n.message_type.equals("callerid_success")) {
                    title = n.network;
                    text = n.nick + " has been added to your accept list";
                    ticker = n.nick + " has been added to your accept list on " + n.network;
                    Intent i = new Intent(RemoteInputService.ACTION_REPLY);
                    i.setComponent(new ComponentName(
                            IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
                            RemoteInputService.class.getName()));
                    i.putExtra("cid", n.cid);
                    i.putExtra("eid", n.eid);
                    i.putExtra("chan", n.chan);
                    i.putExtra("buffer_type", n.buffer_type);
                    i.putExtra("network", n.network);
                    i.putExtra("to", n.nick);
                    action = new NotificationCompat.Action.Builder(R.drawable.ic_wearable_reply, "Message",
                            PendingIntent.getService(IRCCloudApplication.getInstance().getApplicationContext(),
                                    (int) (n.eid / 1000), i, PendingIntent.FLAG_UPDATE_CURRENT))
                                            .setAllowGeneratedReplies(true)
                                            .addRemoteInput(new RemoteInput.Builder("extra_reply")
                                                    .setLabel("Message to " + n.nick).build())
                                            .build();
                } else if (n.message_type.equals("channel_invite")) {
                    title = n.network;
                    text = n.nick + " invited you to join " + n.chan;
                    ticker = text;
                    try {
                        Intent i = new Intent();
                        i.setComponent(new ComponentName(
                                IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
                                "com.irccloud.android.MainActivity"));
                        i.setData(Uri.parse(IRCCloudApplication.getInstance().getResources()
                                .getString(R.string.IRCCLOUD_SCHEME) + "://cid/" + n.cid + "/"
                                + URLEncoder.encode(n.chan, "UTF-8")));
                        i.putExtra("eid", n.eid);
                        action = new NotificationCompat.Action(R.drawable.ic_wearable_add, "Join",
                                PendingIntent.getActivity(
                                        IRCCloudApplication.getInstance().getApplicationContext(),
                                        (int) (n.eid / 1000), i, PendingIntent.FLAG_UPDATE_CURRENT));
                    } catch (Exception e) {
                        action = null;
                    }
                } else {
                    title = n.nick;
                    text = n.message;
                    ticker = n.message;
                    action = null;
                }
                if (title != null && text != null)
                    NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext())
                            .notify((int) (n.eid / 1000), buildNotification(ticker, n.cid, n.bid,
                                    new long[] { n.eid }, title, text, 1, null, n.network, null, action,
                                    AvatarsList.getInstance().getAvatar(n.cid, n.nick).getBitmap(false,
                                            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 64,
                                                    IRCCloudApplication.getInstance().getApplicationContext()
                                                            .getResources().getDisplayMetrics()),
                                            false, Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP),
                                    AvatarsList.getInstance().getAvatar(n.cid, n.nick).getBitmap(false, 400,
                                            false, false)));
            }
        }
        TransactionManager.transact(IRCCloudDatabase.NAME, new Runnable() {
            @Override
            public void run() {
                for (Notification n : notifications) {
                    n.delete();
                }
            }
        });
    }
}

From source file:com.nogago.android.tracks.TrackListActivity.java

/**
 * Handles a context item selection./*from  w w  w . j  a v a  2s  .  co  m*/
 * 
 * @param itemId the menu item id
 * @param trackId the track id
 * @return true if handled.
 */
private boolean handleContextItem(int itemId, long trackId) {
    Intent intent;
    switch (itemId) {

    case R.id.list_context_menu_show_on_map:
        intent = new Intent();
        intent = IntentUtils.newIntent(this, TrackDetailActivity.class);
        intent.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId);
        /** directly to MapActivity
        String nogagoPackage = "com.nogago.android.maps";
        String mapActivity = ".activities.MapActivity";
        intent.setComponent(new ComponentName(nogagoPackage, nogagoPackage + mapActivity));
        intent.putExtra("follow", true);
        startActivity(intent);
        */
        String trackPackage = "com.nogago.android.tracks";
        String trackDetailActivity = ".TrackDetailActivity";
        intent.setComponent(new ComponentName(trackPackage, trackPackage + trackDetailActivity));
        intent.putExtra("fromTrackList", true);

        startActivity(intent);
        return true;

    case R.id.list_context_menu_edit:
        intent = IntentUtils.newIntent(this, TrackEditActivity.class).putExtra(TrackEditActivity.EXTRA_TRACK_ID,
                trackId);
        startActivity(intent);
        return true;
    case R.id.list_context_menu_delete:
        DeleteOneTrackDialogFragment.newInstance(trackId).show(getSupportFragmentManager(),
                DeleteOneTrackDialogFragment.DELETE_ONE_TRACK_DIALOG_TAG);
        return true;
    default:
        return false;
    }
}

From source file:com.aimfire.main.MainActivity.java

/**
 * share only to certain apps. code based on "http://stackoverflow.com/questions/
 * 9730243/how-to-filter-specific-apps-for-action-send-intent-and-set-a-different-
 * text-for/18980872#18980872"/*from  w ww  .  ja  va 2 s.  c  o m*/
 *
 * "copy link" inspired by http://cketti.de/2016/06/15/share-url-to-clipboard/
 *
 * in general, "deep linking" is supported by the apps below. Facebook, Wechat,
 * Telegram are exceptions. click on the link would bring users to the landing
 * page.
 *
 * Facebook doesn't take our EXTRA_TEXT so user will have to "copy link" first
 * then paste the link
 */
private void inviteFriend() {
    mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_INVITE, null);

    Resources resources = getResources();

    /*
     * construct link
     */
    String appLink = resources.getString(R.string.app_store_link);

    /*
     * message subject and text
     */
    String emailSubject, emailText, twitterText;

    emailSubject = resources.getString(R.string.emailSubjectInviteFriend);
    emailText = resources.getString(R.string.emailBodyInviteFriend) + appLink;
    twitterText = resources.getString(R.string.emailBodyInviteFriend) + appLink + ", "
            + resources.getString(R.string.app_hashtag);

    Intent emailIntent = new Intent();
    emailIntent.setAction(Intent.ACTION_SEND);
    // Native email client doesn't currently support HTML, but it doesn't hurt to try in case they fix it
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
    emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
    //emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_native)));
    emailIntent.setType("message/rfc822");

    PackageManager pm = getPackageManager();
    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/plain");

    Intent openInChooser = Intent.createChooser(emailIntent, resources.getString(R.string.share_chooser_text));

    List<ResolveInfo> resInfo = pm.queryIntentActivities(sendIntent, 0);
    List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
    for (int i = 0; i < resInfo.size(); i++) {
        // Extract the label, append it, and repackage it in a LabeledIntent
        ResolveInfo ri = resInfo.get(i);
        String packageName = ri.activityInfo.packageName;
        if (packageName.contains("android.email")) {
            emailIntent.setPackage(packageName);
        } else if (packageName.contains("twitter") || packageName.contains("facebook")
                || packageName.contains("whatsapp") || packageName.contains("tencent.mm") || //wechat
                packageName.contains("line") || packageName.contains("skype") || packageName.contains("viber")
                || packageName.contains("kik") || packageName.contains("sgiggle") || //tango
                packageName.contains("kakao") || packageName.contains("telegram")
                || packageName.contains("nimbuzz") || packageName.contains("hike")
                || packageName.contains("imoim") || packageName.contains("bbm")
                || packageName.contains("threema") || packageName.contains("mms")
                || packageName.contains("android.apps.messaging") || //google messenger
                packageName.contains("android.talk") || //google hangouts
                packageName.contains("android.gm")) {
            Intent intent = new Intent();
            intent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            if (packageName.contains("twitter")) {
                intent.putExtra(Intent.EXTRA_TEXT, twitterText);
            } else if (packageName.contains("facebook")) {
                /*
                 * the warning below is wrong! at least on GS5, Facebook client does take
                 * our text, however it seems it takes only the first hyperlink in the
                 * text.
                 *
                 * Warning: Facebook IGNORES our text. They say "These fields are intended
                 * for users to express themselves. Pre-filling these fields erodes the
                 * authenticity of the user voice."
                 * One workaround is to use the Facebook SDK to post, but that doesn't
                 * allow the user to choose how they want to share. We can also make a
                 * custom landing page, and the link will show the <meta content ="...">
                 * text from that page with our link in Facebook.
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("tencent.mm")) //wechat
            {
                /*
                 * wechat appears to do this similar to Facebook
                 */
                intent.putExtra(Intent.EXTRA_TEXT, appLink);
            } else if (packageName.contains("android.gm")) {
                // If Gmail shows up twice, try removing this else-if clause and the reference to "android.gm" above
                intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
                //intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(resources.getString(R.string.share_email_gmail)));
                intent.setType("message/rfc822");
            } else if (packageName.contains("android.apps.docs")) {
                /*
                 * google drive - no reason to send link to it
                 */
                continue;
            } else {
                intent.putExtra(Intent.EXTRA_TEXT, emailText);
            }

            intentList.add(new LabeledIntent(intent, packageName, ri.loadLabel(pm), ri.icon));
        }
    }

    /*
     *  create "Copy Link To Clipboard" Intent
     */
    Intent clipboardIntent = new Intent(this, CopyToClipboardActivity.class);
    clipboardIntent.setData(Uri.parse(appLink));
    intentList.add(new LabeledIntent(clipboardIntent, getPackageName(),
            getResources().getString(R.string.clipboard_activity_name), R.drawable.ic_copy_link));

    // convert intentList to array
    LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);

    openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
    startActivity(openInChooser);
}

From source file:com.android.documentsui.DocumentsActivity.java

public void onAppPicked(ResolveInfo info) {
    final Intent intent = new Intent(getIntent());
    intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    intent.setComponent(
            new ComponentName(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
    startActivityForResult(intent, CODE_FORWARD);
}

From source file:at.tomtasche.reader.ui.activity.MainActivity.java

public void findDocument() {

    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    // remove mime-type because most apps don't support ODF mime-types
    intent.setType("application/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    PackageManager pm = getPackageManager();
    final List<ResolveInfo> targets = pm.queryIntentActivities(intent, 0);
    int size = targets.size();
    String[] targetNames = new String[size];
    for (int i = 0; i < size; i++) {
        targetNames[i] = targets.get(i).loadLabel(pm).toString();
    }//w  w  w .j  av  a 2 s . c  o  m

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.dialog_choose_filemanager);
    builder.setItems(targetNames, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            ResolveInfo target = targets.get(which);
            if (target == null) {
                return;
            }

            intent.setComponent(new ComponentName(target.activityInfo.packageName, target.activityInfo.name));

            try {
                startActivityForResult(intent, 42);
            } catch (Exception e) {
                e.printStackTrace();

                showCrouton(R.string.crouton_error_open_app, new Runnable() {

                    @Override
                    public void run() {
                        findDocument();
                    }
                }, AppMsg.STYLE_ALERT);
            }

            dialog.dismiss();
        }
    });
    builder.show();
}

From source file:com.android.documentsui.DocumentsActivity.java

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

    mRoots = DocumentsApplication.getRootsCache(this);

    setResult(Activity.RESULT_CANCELED);
    setContentView(R.layout.activity);//from  w  w w.  j ava  2s.  c  o  m

    final Resources res = getResources();
    mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);

    if (mShowAsDialog) {
        // backgroundDimAmount from theme isn't applied; do it manually
        final WindowManager.LayoutParams a = getWindow().getAttributes();
        a.dimAmount = 0.6f;
        getWindow().setAttributes(a);

        getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
        getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

        // Inset ourselves to look like a dialog
        final Point size = new Point();
        getWindowManager().getDefaultDisplay().getSize(size);

        final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x);
        final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y);
        final int insetX = (size.x - width) / 2;
        final int insetY = (size.y - height) / 2;

        final Drawable before = getWindow().getDecorView().getBackground();
        final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY);
        getWindow().getDecorView().setBackground(after);

        // Dismiss when touch down in the dimmed inset area
        getWindow().getDecorView().setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    final float x = event.getX();
                    final float y = event.getY();
                    if (x < insetX || x > v.getWidth() - insetX || y < insetY || y > v.getHeight() - insetY) {
                        finish();
                        return true;
                    }
                }
                return false;
            }
        });

    } else {
        // Non-dialog means we have a drawer
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer_glyph,
                R.string.drawer_open, R.string.drawer_close);

        mDrawerLayout.setDrawerListener(mDrawerListener);
        mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START);

        mRootsContainer = findViewById(R.id.container_roots);
    }

    mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);

    if (icicle != null) {
        mState = icicle.getParcelable(EXTRA_STATE);
    } else {
        buildDefaultState();
    }

    // Hide roots when we're managing a specific root
    if (mState.action == ACTION_MANAGE) {
        if (mShowAsDialog) {
            findViewById(R.id.dialog_roots).setVisibility(View.GONE);
        } else {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        }
    }

    if (mState.action == ACTION_CREATE) {
        final String mimeType = getIntent().getType();
        final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE);
        SaveFragment.show(getFragmentManager(), mimeType, title);
    }

    if (mState.action == ACTION_GET_CONTENT) {
        final Intent moreApps = new Intent(getIntent());
        moreApps.setComponent(null);
        moreApps.setPackage(null);
        RootsFragment.show(getFragmentManager(), moreApps);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_CREATE) {
        RootsFragment.show(getFragmentManager(), null);
    }

    if (!mState.restored) {
        if (mState.action == ACTION_MANAGE) {
            final Uri rootUri = getIntent().getData();
            new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
        } else {
            new RestoreStackTask().execute();
        }
    } else {
        onCurrentDirectoryChanged(ANIM_NONE);
    }
}

From source file:com.yamin.kk.service.AudioService.java

/**
 * Set up the remote control and tell the system we want to be the default receiver for the MEDIA buttons
 * @see http://android-developers.blogspot.fr/2010/06/allowing-applications-to-play-nicer.html
 *//* ww w.j a  v  a2s  .c  o  m*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void setUpRemoteControlClient() {
    Context context = VLCApplication.getAppContext();
    AudioManager audioManager = (AudioManager) context.getSystemService(AUDIO_SERVICE);

    if (Util.isICSOrLater()) {
        audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);

        if (mRemoteControlClient == null) {
            Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
            mediaButtonIntent.setComponent(mRemoteControlClientReceiverComponent);
            PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context, 0, mediaButtonIntent, 0);

            // create and register the remote control client
            mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
            audioManager.registerRemoteControlClient(mRemoteControlClient);
        }

        mRemoteControlClient.setTransportControlFlags(RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE | RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS
                | RemoteControlClient.FLAG_KEY_MEDIA_NEXT | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
    } else if (Util.isFroyoOrLater()) {
        audioManager.registerMediaButtonEventReceiver(mRemoteControlClientReceiverComponent);
    }
}

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

public void onAppPicked(ResolveInfo info) {
    final Intent intent = new Intent(virtualIntent);
    intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_FORWARD_RESULT);
    intent.setComponent(
            new ComponentName(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
    startActivityForResult(intent, CODE_FORWARD);
}