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:android.support.v7.internal.widget.ActivityChooserModel.java

/**
 * Chooses a activity to handle the current intent. This will result in
 * adding a historical record for that action and construct intent with
 * its component name set such that it can be immediately started by the
 * client.// w  ww  .j a v  a  2 s  .c  o  m
 * <p>
 * <strong>Note:</strong> By calling this method the client guarantees
 * that the returned intent will be started. This intent is returned to
 * the client solely to let additional customization before the start.
 * </p>
 *
 * @return An {@link Intent} for launching the activity or null if the
 *         policy has consumed the intent or there is not current intent
 *         set via {@link #setIntent(Intent)}.
 *
 * @see HistoricalRecord
 * @see OnChooseActivityListener
 */
public Intent chooseActivity(int index) {
    synchronized (mInstanceLock) {
        if (mIntent == null) {
            return null;
        }

        ensureConsistentState();

        ActivityResolveInfo chosenActivity = mActivities.get(index);

        ComponentName chosenName = new ComponentName(chosenActivity.resolveInfo.activityInfo.packageName,
                chosenActivity.resolveInfo.activityInfo.name);

        Intent choiceIntent = new Intent(mIntent);
        choiceIntent.setComponent(chosenName);

        if (mActivityChoserModelPolicy != null) {
            // Do not allow the policy to change the intent.
            Intent choiceIntentCopy = new Intent(choiceIntent);
            final boolean handled = mActivityChoserModelPolicy.onChooseActivity(this, choiceIntentCopy);
            if (handled) {
                return null;
            }
        }

        HistoricalRecord historicalRecord = new HistoricalRecord(chosenName, System.currentTimeMillis(),
                DEFAULT_HISTORICAL_RECORD_WEIGHT);
        addHisoricalRecord(historicalRecord);

        return choiceIntent;
    }
}

From source file:com.chummy.jezebel.material.dark.activities.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    context = this;
    mPrefs = new Preferences(Main.this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  w w  w  .j  ava2  s. com
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    thaApp = getResources().getString(R.string.app_name);
    thaHome = getResources().getString(R.string.section_one);
    thaPreviews = getResources().getString(R.string.section_two);
    thaApply = getResources().getString(R.string.section_three);
    thaWalls = getResources().getString(R.string.section_four);
    thaRequest = getResources().getString(R.string.section_five);
    thaCredits = getResources().getString(R.string.section_seven);
    thaTesters = getResources().getString(R.string.section_eight);
    thaWhatIsThemed = getResources().getString(R.string.section_nine);
    thaContactUs = getResources().getString(R.string.section_ten);
    thaLogcat = getResources().getString(R.string.section_eleven);
    thaFAQ = getResources().getString(R.string.section_twelve);
    thaHelp = getResources().getString(R.string.section_thirteen);
    thaAbout = getResources().getString(R.string.section_fourteen);
    thaIconPack = getResources().getString(R.string.section_fifteen);
    thaFullChangelog = getResources().getString(R.string.section_sixteen);
    thaRebuild = getResources().getString(R.string.section_seventeen);

    drawerVersion = getResources().getString(R.string.version_code);

    currentItem = 1;

    headerResult = new AccountHeader().withActivity(this).withHeaderBackground(R.drawable.header)
            .withSelectionFirstLine(getResources().getString(R.string.app_name))
            .withSelectionSecondLine(drawerVersion).withSavedInstance(savedInstanceState).withHeightDp(120)
            .build();

    enable_features = mPrefs.isFeaturesEnabled();
    firstrun = mPrefs.isFirstRun();

    result = new Drawer().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult)
            .withHeaderDivider(false).withDrawerWidthDp(400)
            .addDrawerItems(new SectionDrawerItem().withName("Main"),
                    new PrimaryDrawerItem().withName(thaHome).withIcon(GoogleMaterial.Icon.gmd_home)
                            .withIdentifier(1),
                    new PrimaryDrawerItem().withName(thaIconPack)
                            .withIcon(GoogleMaterial.Icon.gmd_picture_in_picture)
                            .withDescription("This applies icon pack 'Whicons'.").withCheckable(false)
                            .withIdentifier(11),
                    new PrimaryDrawerItem().withName(thaFullChangelog)
                            .withIcon(GoogleMaterial.Icon.gmd_wrap_text)
                            .withDescription("Complete changelog of Dark Material.").withCheckable(false)
                            .withIdentifier(12),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("Information"),
                    new PrimaryDrawerItem().withName(thaAbout).withIcon(GoogleMaterial.Icon.gmd_info_outline)
                            .withDescription("Basic information on the theme.").withIdentifier(10),
                    new PrimaryDrawerItem().withName(thaWhatIsThemed).withIcon(GoogleMaterial.Icon.gmd_warning)
                            .withDescription("List of overlaid applications.").withIdentifier(3),
                    new PrimaryDrawerItem().withName(thaFAQ).withIcon(GoogleMaterial.Icon.gmd_question_answer)
                            .withDescription("Common questions with answers.").withIdentifier(8),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("Tools & Utilities"),
                    new PrimaryDrawerItem().withName(thaRebuild).withIcon(GoogleMaterial.Icon.gmd_sync)
                            .withDescription("A rebuild a day keeps the RRs away!").withCheckable(false)
                            .withBadge("ROOT ").withIdentifier(13),
                    new PrimaryDrawerItem().withName(thaLogcat).withIcon(GoogleMaterial.Icon.gmd_bug_report)
                            .withDescription("System level log recording.").withCheckable(false)
                            .withBadge("ROOT ").withIdentifier(7),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("The Developers"),
                    new PrimaryDrawerItem().withName(thaCredits).withIcon(GoogleMaterial.Icon.gmd_people)
                            .withDescription("chummy development team").withIdentifier(5),
                    new PrimaryDrawerItem().withName(thaTesters).withIcon(GoogleMaterial.Icon.gmd_star)
                            .withDescription("The people who keep the team updated.").withIdentifier(4),
                    new DividerDrawerItem(), new SectionDrawerItem().withName("Contact"),
                    new SecondaryDrawerItem().withName(thaContactUs).withIcon(GoogleMaterial.Icon.gmd_mail)
                            .withCheckable(false).withIdentifier(6),
                    new SecondaryDrawerItem().withName(thaHelp).withIcon(GoogleMaterial.Icon.gmd_help)
                            .withCheckable(true).withIdentifier(9))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id,
                        IDrawerItem drawerItem) {

                    if (drawerItem != null) {

                        switch (drawerItem.getIdentifier()) {
                        case 1:
                            switchFragment(1, thaApp, "Home");
                            break;
                        case 2:
                            ConnectivityManager cm = (ConnectivityManager) context
                                    .getSystemService(Context.CONNECTIVITY_SERVICE);
                            NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
                            boolean isConnected = activeNetwork != null
                                    && activeNetwork.isConnectedOrConnecting();

                            if (isConnected) {
                                switchFragment(2, thaWalls, "Wallpapers");
                            } else {
                                showNotConnectedDialog();
                            }
                            break;
                        case 3:
                            switchFragment(3, thaWhatIsThemed, "WhatIsThemed");
                            break;
                        case 4:
                            switchFragment(4, thaTesters, "Testers");
                            break;
                        case 5:
                            switchFragment(5, thaCredits, "Credits");
                            break;
                        case 6:
                            StringBuilder emailBuilder = new StringBuilder();
                            Intent intent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("mailto:" + getResources().getString(R.string.email_id)));
                            if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
                                if (!isAppInstalled("com.cyngn.theme.chooser")) {
                                    if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                                        intent.putExtra(Intent.EXTRA_SUBJECT,
                                                getResources().getString(R.string.email_subject));
                                    } else {
                                        intent.putExtra(Intent.EXTRA_SUBJECT,
                                                getResources().getString(R.string.email_subject_rro));
                                    }
                                } else {
                                    intent.putExtra(Intent.EXTRA_SUBJECT,
                                            getResources().getString(R.string.email_subject_cos));
                                }
                            } else {
                                intent.putExtra(Intent.EXTRA_SUBJECT,
                                        getResources().getString(R.string.email_subject_cm));
                            }
                            emailBuilder.append("\n \n \nOS Version: " + System.getProperty("os.version") + "("
                                    + Build.VERSION.INCREMENTAL + ")");
                            emailBuilder.append("\nOS API Level: " + Build.VERSION.SDK_INT + " ("
                                    + Build.VERSION.RELEASE + ") " + "[" + Build.ID + "]");
                            emailBuilder.append("\nDevice: " + Build.DEVICE);
                            emailBuilder.append("\nManufacturer: " + Build.MANUFACTURER);
                            emailBuilder.append(
                                    "\nModel (and Product): " + Build.MODEL + " (" + Build.PRODUCT + ")");
                            if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
                                if (!isAppInstalled("com.cyngn.theme.chooser")) {
                                    if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                                        emailBuilder.append("\nTheme Engine: Not Available");
                                    } else {
                                        emailBuilder.append("\nTheme Engine: Layers Manager (RRO)");
                                    }
                                } else {
                                    emailBuilder.append("\nTheme Engine: Cyanogen OS Theme Engine");
                                }
                            } else {
                                emailBuilder.append("\nTheme Engine: CyanogenMod Theme Engine");
                            }
                            PackageInfo appInfo = null;
                            try {
                                appInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
                            } catch (PackageManager.NameNotFoundException e) {
                                e.printStackTrace();
                            }
                            emailBuilder.append("\nApp Version Name: " + appInfo.versionName);
                            emailBuilder.append("\nApp Version Code: " + appInfo.versionCode);

                            intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString());
                            startActivity(Intent.createChooser(intent,
                                    (getResources().getString(R.string.send_title))));
                            break;
                        case 7:
                            if (Shell.SU.available()) {
                                if (!isAppInstalled("com.tooleap.logcat")) {
                                    if (!isAppInstalled("com.nolanlawson.logcat")) {
                                        Intent logcat = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                                getResources().getString(R.string.play_store_link_logcat)));
                                        startActivity(logcat);
                                    } else {
                                        Intent intent_logcat = getPackageManager()
                                                .getLaunchIntentForPackage("com.nolanlawson.logcat");
                                        Toast toast = Toast.makeText(getApplicationContext(),
                                                getResources().getString(R.string.logcat_toast),
                                                Toast.LENGTH_LONG);
                                        toast.show();
                                        startActivity(intent_logcat);
                                    }
                                } else {
                                    Intent intent_tooleap = getPackageManager()
                                            .getLaunchIntentForPackage("com.tooleap.logcat");
                                    Toast toast = Toast.makeText(getApplicationContext(),
                                            getResources().getString(R.string.logcat_toast), Toast.LENGTH_LONG);
                                    toast.show();
                                    startActivity(intent_tooleap);
                                }
                            } else {
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        "Unfortunately, this feature is only available for root users.",
                                        Toast.LENGTH_LONG);
                                toast.show();
                            }
                            break;
                        case 8:
                            switchFragment(8, thaFAQ, "FAQ");
                            break;
                        case 9:
                            switchFragment(9, thaHelp, "Help");
                            break;
                        case 10:
                            switchFragment(10, thaAbout, "About");
                            break;
                        case 11:
                            Intent launch_whicons = new Intent("android.intent.action.MAIN");
                            launch_whicons.setComponent(new ComponentName("org.cyanogenmod.theme.chooser",
                                    "org.cyanogenmod.theme.chooser.ChooserActivity"));
                            launch_whicons.putExtra("pkgName", "com.whicons.iconpack");
                            Intent launch_whicons_cos = new Intent("android.intent.action.MAIN");
                            launch_whicons_cos.setComponent(new ComponentName("com.cyngn.theme.chooser",
                                    "com.cyngn.theme.chooser.ChooserActivity"));
                            launch_whicons_cos.putExtra("pkgName", "com.whicons.iconpack");
                            Intent devPlay = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse(getResources().getString(R.string.play_store_whicons)));
                            Intent intent_whicons = getPackageManager()
                                    .getLaunchIntentForPackage("com.whicons.iconpack");
                            if (intent_whicons == null) {
                                startActivity(devPlay);
                            } else {
                                if (isAppInstalled("org.cyanogenmod.theme.chooser")) {
                                    startActivity(launch_whicons);
                                } else {
                                    if (isAppInstalled("com.cyngn.theme.chooser")) {
                                        Toast toast = Toast.makeText(getApplicationContext(),
                                                "Select Dark Material, click Customize and locate Default Icons. Then select Whicons and click Apply.",
                                                Toast.LENGTH_LONG);
                                        toast.show();
                                        startActivity(launch_whicons_cos);
                                    } else {
                                        startActivity(intent_whicons);
                                    }
                                }
                            }
                            break;
                        case 12:
                            fullchangelog();
                            break;
                        case 13:
                            if (Shell.SU.available()) {
                                rebuildThemeCache();
                            } else {
                                Toast toast = Toast.makeText(getApplicationContext(),
                                        "Unfortunately, this feature is only available for root users.",
                                        Toast.LENGTH_LONG);
                                toast.show();
                            }
                            break;
                        }
                    }
                }
            }).withSavedInstance(savedInstanceState).build();

    result.getListView().setVerticalScrollBarEnabled(false);

    // Check for permissions first so that we don't have any issues down the road
    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(),
            android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
        // permission already granted, allow the program to continue running
        runLicenseChecker();
    } else {
        // permission not granted, request it from the user
        ActivityCompat.requestPermissions(this,
                new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE },
                PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
    }

    if (savedInstanceState == null) {
        result.setSelectionByIdentifier(1);
    }

}

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

public NotificationCompat.Builder alert(int bid, String title, String body) {
    Crashlytics.log(Log.DEBUG, "IRCCloud", "Posting alert notification");
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            IRCCloudApplication.getInstance().getApplicationContext()).setContentTitle(title)
                    .setContentText(body).setTicker(body).setAutoCancel(true)
                    .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources()
                            .getColor(R.color.ic_background))
                    .setSmallIcon(R.drawable.ic_stat_notify);

    Intent i = new Intent();
    i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
            "com.irccloud.android.MainActivity"));
    i.putExtra("bid", bid);
    i.setData(Uri.parse("bid://" + bid));
    builder.setContentIntent(/*from www  .ja va 2  s  . c  o  m*/
            PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                    PendingIntent.FLAG_UPDATE_CURRENT));

    NotificationManagerCompat.from(IRCCloudApplication.getInstance().getApplicationContext()).notify(bid,
            builder.build());

    return builder;
}

From source file:org.videolan.vlc.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
 *//*  w  ww.jav a  2s  .  co  m*/
@TargetApi(14)
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:net.sourceforge.servestream.service.AppWidgetOneProvider.java

/**
 * Link up various button actions using {@link PendingIntents}.
 * //from  w  w  w  . ja  v a2  s .  c  o  m
 * @param playerActive True if player is active in background, which means
 *            widget click will launch {@link MediaPlayerActivity},
 *            otherwise we launch {@link UriListActivity}.
 */
private void linkButtons(Context context, RemoteViews views, boolean playerActive) {
    // Connect up various buttons and touch events
    Intent intent;
    PendingIntent pendingIntent;

    final ComponentName serviceName = new ComponentName(context, MediaPlaybackService.class);

    if (playerActive) {
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntentWithParentStack(
                new Intent(context, MediaPlayerActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
        pendingIntent = stackBuilder.getPendingIntent((int) System.currentTimeMillis(), 0);
        views.setOnClickPendingIntent(R.id.appwidget_two, pendingIntent);
    } else {
        intent = new Intent(context, MainActivity.class);
        pendingIntent = PendingIntent.getActivity(context, 0 /* no requestCode */, intent, 0 /* no flags */);
        views.setOnClickPendingIntent(R.id.appwidget_two, pendingIntent);
    }

    intent = new Intent(MediaPlaybackService.PREVIOUS_ACTION);
    intent.setComponent(serviceName);
    pendingIntent = PendingIntent.getService(context, 0 /* no requestCode */, intent, 0 /* no flags */);
    views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);

    intent = new Intent(MediaPlaybackService.TOGGLEPAUSE_ACTION);
    intent.setComponent(serviceName);
    pendingIntent = PendingIntent.getService(context, 0 /* no requestCode */, intent, 0 /* no flags */);
    views.setOnClickPendingIntent(R.id.control_play, pendingIntent);

    intent = new Intent(MediaPlaybackService.NEXT_ACTION);
    intent.setComponent(serviceName);
    pendingIntent = PendingIntent.getService(context, 0 /* no requestCode */, intent, 0 /* no flags */);
    views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
}

From source file:com.actionbarsherlock.widget.ActivityChooserModel.java

/**
 * Chooses a activity to handle the current intent. This will result in
 * adding a historical record for that action and construct intent with
 * its component name set such that it can be immediately started by the
 * client./*from   w  w  w .  j  a  v a 2  s. c  o  m*/
 * <p>
 * <strong>Note:</strong> By calling this method the client guarantees
 * that the returned intent will be started. This intent is returned to
 * the client solely to let additional customization before the start.
 * </p>
 *
 * @return An {@link Intent} for launching the activity or null if the
 *         policy has consumed the intent.
 *
 * @see HistoricalRecord
 * @see OnChooseActivityListener
 */
public Intent chooseActivity(int index) {
    ActivityResolveInfo chosenActivity = mActivites.get(index);

    ComponentName chosenName = new ComponentName(chosenActivity.resolveInfo.activityInfo.packageName,
            chosenActivity.resolveInfo.activityInfo.name);

    Intent choiceIntent = new Intent(mIntent);
    choiceIntent.setComponent(chosenName);

    if (mActivityChoserModelPolicy != null) {
        // Do not allow the policy to change the intent.
        Intent choiceIntentCopy = new Intent(choiceIntent);
        final boolean handled = mActivityChoserModelPolicy.onChooseActivity(this, choiceIntentCopy);
        if (handled) {
            return null;
        }
    }

    HistoricalRecord historicalRecord = new HistoricalRecord(chosenName, System.currentTimeMillis(),
            DEFAULT_HISTORICAL_RECORD_WEIGHT);
    addHisoricalRecord(historicalRecord);

    return choiceIntent;
}

From source file:com.irccloud.android.Notifications.java

@SuppressLint("NewApi")
private android.app.Notification buildNotification(String ticker, int bid, long[] eids, String title,
        String text, Spanned big_text, int count, Intent replyIntent, Spanned wear_text, String network,
        String auto_messages[]) {
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext());

    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            IRCCloudApplication.getInstance().getApplicationContext())
                    .setContentTitle(title + ((network != null) ? (" (" + network + ")") : ""))
                    .setContentText(Html.fromHtml(text)).setAutoCancel(true).setTicker(ticker)
                    .setWhen(eids[0] / 1000).setSmallIcon(R.drawable.ic_stat_notify)
                    .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources()
                            .getColor(R.color.dark_blue))
                    .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
                    .setCategory(NotificationCompat.CATEGORY_MESSAGE)
                    .setPriority(NotificationCompat.PRIORITY_HIGH).setOnlyAlertOnce(false);

    if (ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 10000) {
        if (prefs.getBoolean("notify_vibrate", true))
            builder.setDefaults(android.app.Notification.DEFAULT_VIBRATE);
        String ringtone = prefs.getString("notify_ringtone", "content://settings/system/notification_sound");
        if (ringtone != null && ringtone.length() > 0)
            builder.setSound(Uri.parse(ringtone));
    }//w w  w .j  ava2s .  co m

    int led_color = Integer.parseInt(prefs.getString("notify_led_color", "1"));
    if (led_color == 1) {
        if (prefs.getBoolean("notify_vibrate", true))
            builder.setDefaults(
                    android.app.Notification.DEFAULT_LIGHTS | android.app.Notification.DEFAULT_VIBRATE);
        else
            builder.setDefaults(android.app.Notification.DEFAULT_LIGHTS);
    } else if (led_color == 2) {
        builder.setLights(0xFF0000FF, 500, 500);
    }

    SharedPreferences.Editor editor = prefs.edit();
    editor.putLong("lastNotificationTime", System.currentTimeMillis());
    editor.commit();

    Intent i = new Intent();
    i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
            "com.irccloud.android.MainActivity"));
    i.putExtra("bid", bid);
    i.setData(Uri.parse("bid://" + bid));
    Intent dismiss = new Intent(IRCCloudApplication.getInstance().getApplicationContext().getResources()
            .getString(R.string.DISMISS_NOTIFICATION));
    dismiss.setData(Uri.parse("irccloud-dismiss://" + bid));
    dismiss.putExtra("bid", bid);
    dismiss.putExtra("eids", eids);

    PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(
            IRCCloudApplication.getInstance().getApplicationContext(), 0, dismiss,
            PendingIntent.FLAG_UPDATE_CURRENT);

    builder.setContentIntent(
            PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                    PendingIntent.FLAG_UPDATE_CURRENT));
    builder.setDeleteIntent(dismissPendingIntent);

    if (replyIntent != null) {
        WearableExtender extender = new WearableExtender();
        PendingIntent replyPendingIntent = PendingIntent.getService(
                IRCCloudApplication.getInstance().getApplicationContext(), bid + 1, replyIntent,
                PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
        extender.addAction(
                new NotificationCompat.Action.Builder(R.drawable.ic_reply, "Reply", replyPendingIntent)
                        .addRemoteInput(
                                new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build())
                        .build());

        if (count > 1 && wear_text != null)
            extender.addPage(
                    new NotificationCompat.Builder(IRCCloudApplication.getInstance().getApplicationContext())
                            .setContentText(wear_text).extend(new WearableExtender().setStartScrollBottom(true))
                            .build());

        NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder(
                title + ((network != null) ? (" (" + network + ")") : ""))
                        .setReadPendingIntent(dismissPendingIntent).setReplyAction(replyPendingIntent,
                                new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build());

        if (auto_messages != null) {
            for (String m : auto_messages) {
                if (m != null && m.length() > 0) {
                    unreadConvBuilder.addMessage(m);
                }
            }
        } else {
            unreadConvBuilder.addMessage(text);
        }
        unreadConvBuilder.setLatestTimestamp(eids[count - 1] / 1000);

        builder.extend(extender)
                .extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build()));
    }

    if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) {
        i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class);
        i.setData(Uri.parse("irccloud-bid://" + bid));
        i.putExtras(replyIntent);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent quickReplyIntent = PendingIntent.getActivity(
                IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                PendingIntent.FLAG_UPDATE_CURRENT);
        builder.addAction(R.drawable.ic_action_reply, "Quick Reply", quickReplyIntent);
    }

    android.app.Notification notification = builder.build();

    RemoteViews contentView = new RemoteViews(
            IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification);
    contentView.setTextViewText(R.id.title, title + " (" + network + ")");
    contentView.setTextViewText(R.id.text,
            (count == 1) ? Html.fromHtml(text) : (count + " unread highlights."));
    contentView.setLong(R.id.time, "setTime", eids[0] / 1000);
    notification.contentView = contentView;

    if (Build.VERSION.SDK_INT >= 16 && big_text != null) {
        RemoteViews bigContentView = new RemoteViews(
                IRCCloudApplication.getInstance().getApplicationContext().getPackageName(),
                R.layout.notification_expanded);
        bigContentView.setTextViewText(R.id.title,
                title + (!title.equals(network) ? (" (" + network + ")") : ""));
        bigContentView.setTextViewText(R.id.text, big_text);
        bigContentView.setLong(R.id.time, "setTime", eids[0] / 1000);
        if (count > 3) {
            bigContentView.setViewVisibility(R.id.more, View.VISIBLE);
            bigContentView.setTextViewText(R.id.more, "+" + (count - 3) + " more");
        } else {
            bigContentView.setViewVisibility(R.id.more, View.GONE);
        }
        if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) {
            bigContentView.setViewVisibility(R.id.actions, View.VISIBLE);
            bigContentView.setViewVisibility(R.id.action_divider, View.VISIBLE);
            i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class);
            i.setData(Uri.parse("irccloud-bid://" + bid));
            i.putExtras(replyIntent);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            PendingIntent quickReplyIntent = PendingIntent.getActivity(
                    IRCCloudApplication.getInstance().getApplicationContext(), 0, i,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            bigContentView.setOnClickPendingIntent(R.id.action_reply, quickReplyIntent);
        }
        notification.bigContentView = bigContentView;
    }

    return notification;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToSharedAppFeedObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    try {//from   w w  w .  j  av  a 2  s .  co  m
        String packageName = obj.getString(PACKAGE_NAME);
        String feedName = obj.getString("sharedFeedName");
        JSONArray ids = obj.getJSONArray(PARTICIPANTS);
        Intent launch = new Intent();
        launch.setAction(Intent.ACTION_MAIN);
        launch.addCategory(Intent.CATEGORY_LAUNCHER);
        launch.putExtra("type", "invite_app_feed");
        launch.putExtra("creator", false);
        launch.putExtra("sender", from.id);
        launch.putExtra("sharedFeedName", feedName);
        launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        long[] idArray = new long[ids.length()];
        for (int i = 0; i < ids.length(); i++) {
            idArray[i] = ids.getLong(i);
        }
        launch.putExtra("participants", idArray);
        launch.setPackage(packageName);
        final PackageManager mgr = context.getPackageManager();
        List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0);
        if (resolved.size() == 0) {
            Toast.makeText(context, "Could not find application to handle invite.", Toast.LENGTH_SHORT).show();
            return;
        }
        ActivityInfo info = resolved.get(0).activityInfo;
        launch.setComponent(new ComponentName(info.packageName, info.name));
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
                PendingIntent.FLAG_CANCEL_CURRENT);

        (new PresenceAwareNotify(context)).notify("New Invitation from " + from.name,
                "Invitation received from " + from.name, "Click to launch application: " + packageName,
                contentIntent);
    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
    }
}

From source file:org.restcomm.app.qoslib.Services.Intents.IntentHandler.java

private void postSurvey(int surveyid) {
    int icon = 0;
    int customIcon = (owner.getResources().getInteger(R.integer.CUSTOM_NOTIFIER));
    if (customIcon == 0)
        icon = R.drawable.ic_stat_mmcactive;
    else//from w ww.j ava2 s . c o m
        icon = R.drawable.ic_stat_notification_icon;

    if (surveyid > 0) {

        int curr_id = PreferenceManager.getDefaultSharedPreferences(owner).getInt("surveyid", 0);

        if (curr_id == surveyid)
            return;
        //resultIntent.putExtra("id", surveyid);
        requestQuestions(surveyid);
    } else { //default survey id = 1
        //resultIntent.putExtra("id",1);
        requestQuestions(1);
    }

    String message = owner.getString(R.string.survey_notification);
    NotificationManager notificationManager = (NotificationManager) owner
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    Intent notificationIntent = new Intent();
    notificationIntent.setComponent(
            new ComponentName(owner.getPackageName(), "com.cortxt.app.mmcui.Activities.SatisfactionSurvey"));
    notificationIntent.putExtra("id", surveyid);
    notificationIntent.setData((Uri.parse("foobar://" + SystemClock.elapsedRealtime())));
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    int MMC_SURVEY_NOTIFICATION = 8011;
    PendingIntent pendingIntent = PendingIntent.getActivity(owner, MMC_SURVEY_NOTIFICATION + surveyid,
            notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    notification.setLatestEventInfo(owner, message, message, pendingIntent);
    notificationManager.notify(MMC_SURVEY_NOTIFICATION, notification);
}

From source file:com.allwinner.theatreplayer.launcher.activity.LaunchActivity.java

@Override
public void onClick(View view) {
    CellInfo cellInfo = (CellInfo) view.getTag();

    //      Log.i("jim", "1111111111111=======cellInfo.packageName = "+cellInfo.packageName);

    if (cellInfo != null && mLauncherModel != null) {
        //         Log.i("jim", "22222222222=======cellInfo.packageName = "+cellInfo.packageName);
        if (cellInfo.packageName.equals(Constants.PACKAGE_QQ)
                && SharedPreUtil.isFirstRunQQ(Constants.PACKAGE_QQ)) {
            LauncherApp.gIsFirstRunQQ = true;
            SharedPreUtil.saveQQVersionNum(Constants.PACKAGE_QQ);
            if (!OrientatorService.mIsClose) {
                OrientatorService.closeOrientatorMode();
            }/* w  ww.  j a v  a 2  s . co m*/
        } else if (cellInfo.portrait.equals("true")) {
            if (LoadApplicationInfo.isInstalled(this, cellInfo.packageName)) {
                if (!OrientatorService.mIsClose) {
                    OrientatorService.closeOrientatorMode();
                }
            }

        } else {
            if (OrientatorService.mIsClose) {
                OrientatorService.forceLandscapeMode();
            }
        }
        //         Log.i("jim", "3333333=======cellInfo.packageName = "+cellInfo.packageName);
        if (cellInfo.packageName.equals(Constants.PACKAGE_VODTYPE)) {
            mLauncherModel.startVstByType(cellInfo.className, Constants.PACKAGE_VODTYPE);
            //            Log.i("jim", "4444444444444=======cellInfo.packageName = "+cellInfo.packageName);

        } else if (cellInfo.packageName.equals(Constants.PACKAGE_VST_RECORD)
                || cellInfo.packageName.equals(Constants.PACKAGE_VST_SETTING)) {
            mLauncherModel.startActivityByAction(cellInfo.packageName);
            //            Log.i("jim", "5555555555=======cellInfo.packageName = "+cellInfo.packageName);
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_GALLERY)) {
            if (cellInfo.className.equals(Constants.PACKAGE_CAMERA)) {
                //               Log.i("jim", "66666666666=======cellInfo.packageName = "+cellInfo.packageName);
                try {
                    ComponentName componentName = new ComponentName(Constants.PACKAGE_GALLERY,
                            Constants.PACKAGE_CAMERA);
                    Intent intent = new Intent();
                    intent.setComponent(componentName);
                    startActivity(intent);
                } catch (Exception e) {
                    Toast.makeText(this, cellInfo.packageName + " not found", Toast.LENGTH_SHORT).show();
                }
            } else {
                mLauncherModel.startThirdApk(Constants.PACKAGE_GALLERY, cellInfo.className);
                //               Log.i("jim", "7777777777777777=======cellInfo.packageName = "+cellInfo.packageName);
            }

        } else if (cellInfo.packageName.equals(Constants.PACKAGE_OCOCCI_VIDEO)) {
            //            Log.i("jim", "AAAAAAAAAAAA=======cellInfo.packageName = "+cellInfo.packageName);
            //if(cellInfo.className.equals("tv")){               

            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            ComponentName cn = new ComponentName(Constants.PACKAGE_OCOCCI_VIDEO,
                    "com.ococci.video.activity.WelcomeActivity");
            intent.putExtra("video_request_flag", cellInfo.className);
            intent.setComponent(cn);
            startActivity(intent);

            //}
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_HEALTH)) {
            Intent intent = new Intent();
            intent.setAction("com.vst.allwinner.intent.action.ChannelActivity");
            intent.putExtra("cid", cellInfo.className);//
            startActivity(intent);
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_CHILDREN)) {

            Intent intent = new Intent();
            intent.setAction("myvst.intent.action.children.list.v2");
            intent.putExtra("uuid", "424C4C7347456F6F1CF462");
            intent.putExtra("playerIndex", 1);
            startActivity(intent);
        } else if (cellInfo.className != null && !cellInfo.className.equals("")) {
            mLauncherModel.startActivity(cellInfo.packageName, cellInfo.className);

            //            Log.i("jim", "88888888888=======cellInfo.packageName = "+cellInfo.packageName);
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_LIVE)) {
            //            Log.i("jim", "999999999999999=======cellInfo.packageName = "+cellInfo.packageName);
            if (mLiveAppAuthorized) {
                mLauncherModel.startThirdApk(cellInfo.packageName);
            } else {
                CustomToast.showToast(this, R.string.live_unauthorized);
            }
        } else if (cellInfo.packageName.equals("com.allwinner.theatreplayer.launcher.AllAppActivity")) {
            //             Log.i("Trim", cellInfo.packageName);

            Intent intent = new Intent(LaunchActivity.this, LocalAppActivity.class);
            startActivity(intent);
        } else if (cellInfo.packageName.equals("com.android.settings")) {
            //R16settings
            if (Utils.isPkgInstalled(LaunchActivity.this, Constants.PACKAGE_SETTINGS)) {
                mLauncherModel.startThirdApk(Constants.PACKAGE_SETTINGS);
            } else {
                mLauncherModel.startThirdApk(cellInfo.packageName);
            }
        } else {
            //            Log.i("Trim", cellInfo.packageName);
            mLauncherModel.startThirdApk(cellInfo.packageName);
        }
    }
}