Example usage for android.content Intent addCategory

List of usage examples for android.content Intent addCategory

Introduction

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

Prototype

public @NonNull Intent addCategory(String category) 

Source Link

Document

Add a new category to the intent.

Usage

From source file:com.google.android.gms.nearby.messages.samples.nearbybackgroundbeacons.BackgroundSubscribeIntentService.java

private void updateNotification() {
    List<String> messages = Utils.getCachedMessages(getApplicationContext());
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    Intent launchIntent = new Intent(getApplicationContext(), MainActivity.class);
    launchIntent.setAction(Intent.ACTION_MAIN);
    launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, launchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    String contentTitle = getContentTitle(messages);
    String contentText = getContentText(messages);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(android.R.drawable.star_on).setContentTitle(contentTitle).setContentText(contentText)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(contentText)).setOngoing(true)
            .setContentIntent(pi);//from   w  w w  .  ja  v a  2s . c  o m
    notificationManager.notify(MESSAGES_NOTIFICATION_ID, notificationBuilder.build());
}

From source file:com.android.idearse.Login.java

public void onBackPressed() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);//from ww  w . j a  v  a  2 s .c  o  m
}

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

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String mimeType = obj.optString(MIME_TYPE);
    Uri uri = Uri.parse(obj.optString(URI));
    if (fileAvailable(mimeType, uri)) {
        Intent i = new Intent();
        i.setAction(Intent.ACTION_VIEW);
        i.addCategory(Intent.CATEGORY_DEFAULT);
        i.setType(mimeType);//from ww w . ja v a2  s.c  om
        i.setData(uri);
        i.putExtra(Intent.EXTRA_TEXT, uri);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i,
                PendingIntent.FLAG_CANCEL_CURRENT);
        (new PresenceAwareNotify(context)).notify("New content from Musubi", "New Content from Musubi",
                mimeType + "  " + uri, contentIntent);
    } else {
        Log.w(TAG, "Received file, failed to handle: " + uri);
    }
}

From source file:com.chromium.fontinstaller.ui.settings.SettingsFragment.java

private boolean viewSource() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.setData(Uri.parse("https://github.com/ItsPriyesh/FontInstaller"));
    startActivity(intent);/*  w  w  w  .  ja  v a  2s. c o m*/
    return true;
}

From source file:me.xingrz.finder.EntriesActivity.java

protected Intent intentToView(Uri uri, String mime) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(uri, mime);/*ww  w  .java 2  s.  c o m*/
    intent.addCategory(Intent.CATEGORY_DEFAULT);

    for (ResolveInfo resolved : getPackageManager().queryIntentActivities(intent, 0)) {
        if (BuildConfig.APPLICATION_ID.equals(resolved.activityInfo.packageName)) {
            intent.setClassName(this, resolved.activityInfo.name);
            intent.putExtra(EXTRA_ALLOW_BACK, true);
        }
    }

    return intent;
}

From source file:com.android.test.uibench.MainActivity.java

protected List<Map<String, Object>> getData(String prefix) {
    List<Map<String, Object>> myData = new ArrayList<>();

    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(CATEGORY_HWUI_TEST);

    PackageManager pm = getPackageManager();
    List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);

    if (null == list)
        return myData;

    String[] prefixPath;/*from w w w.ja  v  a2 s  .com*/
    String prefixWithSlash = prefix;

    if (prefix.equals("")) {
        prefixPath = null;
    } else {
        prefixPath = prefix.split("/");
        prefixWithSlash = prefix + "/";
    }

    int len = list.size();

    Map<String, Boolean> entries = new HashMap<>();

    for (int i = 0; i < len; i++) {
        ResolveInfo info = list.get(i);
        CharSequence labelSeq = info.loadLabel(pm);
        String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;

        if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {

            String[] labelPath = label.split("/");

            String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];

            if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
                addItem(myData, nextLabel,
                        activityIntent(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
            } else {
                if (entries.get(nextLabel) == null) {
                    addItem(myData, nextLabel,
                            browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
                    entries.put(nextLabel, true);
                }
            }
        }
    }

    Collections.sort(myData, sDisplayNameComparator);

    return myData;
}

From source file:com.google.android.car.kitchensink.cluster.InstrumentClusterFragment.java

private void startNavActivity() {
    CarInstrumentClusterManager clusterManager;
    try {/*  w w  w .j  a v a  2s.  c o  m*/
        clusterManager = (CarInstrumentClusterManager) mCarApi
                .getCarManager(android.car.Car.CAR_INSTRUMENT_CLUSTER_SERVICE);
    } catch (CarNotConnectedException e) {
        Log.e(TAG, "Failed to get CarInstrumentClusterManager", e);
        Toast.makeText(getContext(), "Failed to get CarInstrumentClusterManager", Toast.LENGTH_LONG).show();
        return;
    }

    // Implicit intent
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(CarInstrumentClusterManager.CATEGORY_NAVIGATION);
    try {
        clusterManager.startActivity(intent);
    } catch (android.car.CarNotConnectedException e) {
        Log.e(TAG, "Failed to startActivity in cluster", e);
        Toast.makeText(getContext(), "Failed to start activity in cluster", Toast.LENGTH_LONG).show();
        return;
    }
}

From source file:com.android.talkbacktests.testsession.NotificationTest.java

private void showCustomNotification() {
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext()).setAutoCancel(true)
            .setSmallIcon(android.R.drawable.ic_notification_overlay)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

    RemoteViews contentView = new RemoteViews(getContext().getPackageName(), R.layout.custom_notification);
    contentView.setImageViewResource(R.id.notification_image, android.R.drawable.ic_dialog_email);
    contentView.setTextViewText(R.id.notification_title, getString(R.string.custom_notification_title));
    contentView.setTextViewText(R.id.notification_text, getString(R.string.custom_notification_text));
    builder.setContent(contentView);/*from w  w  w .j a v  a2  s .c om*/

    Intent resultIntent = new Intent(getContext(), MainActivity.class);
    resultIntent.setAction(Intent.ACTION_MAIN);
    resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, resultIntent, 0);
    builder.setContentIntent(pendingIntent);

    NotificationManager notificationManager = (NotificationManager) getContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID_LAST_VIEW, builder.build());
}

From source file:com.google.android.gms.nearby.messages.samples.hellobeacons.BackgroundSubscribeIntentService.java

private void updateNotification() {
    List<String> messages = Utils.getCachedMessages(getApplicationContext());
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    Intent launchIntent = new Intent(getApplicationContext(), MainActivity.class);
    launchIntent.setAction(Intent.ACTION_MAIN);
    launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, launchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    String contentTitle = getContentTitle(messages);
    String contentText = "Deseja abrir a porta?";

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_digitaldesk_big).setContentTitle(contentTitle)
            .setContentText(contentText).setStyle(new NotificationCompat.BigTextStyle().bigText(contentText))
            .setOngoing(false).setContentIntent(pi);
    notificationManager.notify(MESSAGES_NOTIFICATION_ID, notificationBuilder.build());
}

From source file:com.mono.applink.Foursquare.java

/** Called when the activity is first created. */
@Override/*from w  ww .ja va 2s  .c  o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final String url = getIntent().getData().toString();

    if (url.contains("user"))//user with id
    {
        new FoursquareUser().execute();
    } else if (url.contains("venue")) {
        new FoursquareVenue().execute();
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Sorry, but this type of link is not currently supported");
        builder.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        builder.setPositiveButton("Open in Browser", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = new Intent();
                i.setAction("android.intent.action.VIEW");
                i.addCategory("android.intent.category.BROWSABLE");
                i.setComponent(new ComponentName("com.android.browser", "com.android.browser.BrowserActivity"));
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                i.setData(Uri.parse(url));
                startActivity(i);
                finish();
            }
        });
        AlertDialog alert = builder.create();
        alert.show();
    }

}