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.example.android.storageclient.StorageClientFragment.java

/**
 * Fires an intent to spin up the "file chooser" UI and select an image.
 *///from  ww w.  j  a v  a  2 s .c  o m
public void performFileSearch() {

    // BEGIN_INCLUDE (use_open_document_intent)
    // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file browser.
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

    // Filter to only show results that can be "opened", such as a file (as opposed to a list
    // of contacts or timezones)
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // Filter to show only images, using the image MIME data type.
    // If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
    // To search for all documents available via installed storage providers, it would be
    // "*/*".
    intent.setType("image/*");

    startActivityForResult(intent, READ_REQUEST_CODE);
    // END_INCLUDE (use_open_document_intent)
}

From source file:fr.mixit.android.ui.StarredActivity.java

/** Build and add "sessions" tab. */
private void setupSessionsTab() {
    final TabHost host = getTabHost();

    final Uri uri = MixItContract.Sessions.CONTENT_STARRED_URI.buildUpon()
            .appendQueryParameter(MixItContract.SessionCounts.SESSION_INDEX_EXTRAS, Boolean.TRUE.toString())
            .build();/*from w w w  .  j  a va2 s .  c om*/
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.addCategory(Intent.CATEGORY_TAB);
    final boolean highlightParalleStarred = settingsPrefs
            .getBoolean(getString(R.string.visualize_parallel_starred_sessions_key), false);
    intent.putExtra(SessionsActivity.EXTRA_HIHGLIGHT_PARALLEL_STARRED, highlightParalleStarred);
    intent.putExtra(SessionsActivity.EXTRA_FOCUS_CURRENT_NEXT_SESSION, true);

    // Sessions content comes from reused activity
    host.addTab(host.newTabSpec(TAG_SESSIONS).setIndicator(buildIndicator(R.string.starred_sessions))
            .setContent(intent));
}

From source file:edu.mines.letschat.GcmIntentService.java

protected PendingIntent getDeleteIntent() {
    Intent resultBroadCastIntent = new Intent();
    resultBroadCastIntent.setAction("deletion");
    resultBroadCastIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    resultBroadCastIntent.addCategory(Intent.CATEGORY_DEFAULT);
    sendBroadcast(resultBroadCastIntent);
    return PendingIntent.getBroadcast(getBaseContext(), 0, resultBroadCastIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void openFileChooser(Activity activity, String mimeType, int requestCode) {

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType(mimeType);/*from w ww. j a  v  a  2  s . c o  m*/
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // special intent for Samsung file manager
    Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA");

    sIntent.putExtra("CONTENT_TYPE", mimeType);
    sIntent.addCategory(Intent.CATEGORY_DEFAULT);

    Intent chooserIntent;
    if (activity.getPackageManager().resolveActivity(sIntent, 0) != null) {
        chooserIntent = Intent.createChooser(sIntent, "Open file");
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent });
    } else {
        chooserIntent = Intent.createChooser(intent, "Open file");
    }

    if (chooserIntent != null) {
        try {
            activity.startActivityForResult(chooserIntent, requestCode);
            return;
        } catch (android.content.ActivityNotFoundException ex) {
        }
    }
    Toast.makeText(activity.getApplicationContext(),
            activity.getResources().getString(R.string.no_file_chooser), Toast.LENGTH_SHORT).show();
}

From source file:com.example.android.CreateNewPlayer.java

/** Called when the user clicks the Choose Image button */
public void pickImage(View View) {
    playButton();/*from w ww .j  ava 2 s . co  m*/
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, REQUEST_CODE);
}

From source file:ca.rmen.android.poetassistant.main.reader.ReaderFragment.java

@TargetApi(Build.VERSION_CODES.KITKAT)
private void saveAs() {
    Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("text/plain");
    PoemFile poemFile = mPoemPrefs.getSavedPoem();
    final String fileName;
    if (poemFile != null) {
        fileName = poemFile.name;/* ww w  .  j a v a  2 s  .c  o  m*/
    } else {
        fileName = PoemFile.generateFileName(mBinding.tvText.getText().toString());
    }
    if (!TextUtils.isEmpty(fileName))
        intent.putExtra(Intent.EXTRA_TITLE, fileName);
    startActivityForResult(intent, ACTION_FILE_SAVE_AS);
}

From source file:com.airbop.library.simple.AirBopGCMIntentService.java

private static void generateNotification(Context context, String title, String message, String url,
        String large_icon) {// ww  w.j av a 2  s .c om

    //int icon = R.drawable.ic_stat_gcm;
    AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context);

    int icon = airBop_settings.mNotificationIcon;

    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    //if ((title == null) || (title.equals(""))) {
    if (title == null) {
        title = airBop_settings.mDefaultNotificationTitle;
    }

    Intent notificationIntent = null;
    if ((url == null) || (url.equals(""))) {
        //just bring up the app
        if (context != null) {
            ClassLoader class_loader = context.getClassLoader();
            if (class_loader != null) {
                try {
                    if (airBop_settings.mDefaultNotificationClass != null) {
                        notificationIntent = new Intent(context,
                                Class.forName(airBop_settings.mDefaultNotificationClass));
                    }
                } catch (ClassNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    //notificationIntent = new Intent(Intent.ACTION_VIEW);
                }
            }
        }

    } else {
        //Launch the URL
        notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setData(Uri.parse(url));
        notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE);
    }
    PendingIntent intent = null;
    // set intent so it does not start a new activity
    if (notificationIntent != null) {
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    }

    Builder notificationBuilder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message).setLargeIcon(decodeImage(large_icon)).setWhen(when)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message));
    if (intent != null) {
        notificationBuilder.setContentIntent(intent);
    }
    if (icon != 0) {
        notificationBuilder.setSmallIcon(icon);
    }
    Notification notification = notificationBuilder.build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);

}

From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java

private boolean currentLauncherSupportsManagedProfiles() {
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);

    PackageManager pm = getPackageManager();
    ResolveInfo launcherResolveInfo = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
    if (launcherResolveInfo == null) {
        return false;
    }//from www  . ja v  a 2s .  c o  m
    try {
        ApplicationInfo launcherAppInfo = getPackageManager()
                .getApplicationInfo(launcherResolveInfo.activityInfo.packageName, 0 /* default flags */);
        return versionNumberAtLeastL(launcherAppInfo.targetSdkVersion);
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

From source file:com.artech.android.gcm.GcmIntentService.java

@SuppressLint("InlinedApi")
public void createNotification(String payload, String action, String notificationParameters) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    String appName = getString(R.string.app_name);

    SharedPreferences settings = MyApplication.getInstance().getAppSharedPreferences();
    int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications //$NON-NLS-1$

    Intent intent = new Intent("android.intent.action.MAIN"); //$NON-NLS-1$
    intent.setClassName(this, getPackageName() + ".Main"); //$NON-NLS-1$
    intent.addCategory("android.intent.category.LAUNCHER"); //$NON-NLS-1$

    if (Services.Strings.hasValue(action)) {
        // call main as root of the stack with the action as intent parameter. Use clear_task like GoHome
        if (CompatibilityHelper.isApiLevel(Build.VERSION_CODES.HONEYCOMB))
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        else//from w w  w  .  j  av a 2s . c  o  m
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

        intent.putExtra(IntentParameters.NotificationAction, action);
        intent.putExtra(IntentParameters.NotificationParameters, notificationParameters);
        intent.setAction(String.valueOf(Math.random()));
    } else {
        // call main like main application shortcut
        intent.setFlags(0);
        intent.setAction("android.intent.action.MAIN");
    }

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    Notification notification = NotificationHelper.newBuilder(this).setWhen(System.currentTimeMillis())
            .setContentTitle(appName).setContentText(payload).setContentIntent(pendingIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(payload))
            .setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true).build();

    notificationManager.notify(notificatonID, notification);

    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("notificationID", ++notificatonID % 32); //$NON-NLS-1$
    editor.commit();
}