Example usage for android.content Intent CATEGORY_ALTERNATIVE

List of usage examples for android.content Intent CATEGORY_ALTERNATIVE

Introduction

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

Prototype

String CATEGORY_ALTERNATIVE

To view the source code for android.content Intent CATEGORY_ALTERNATIVE.

Click Source Link

Document

Set if the activity should be considered as an alternative action to the data the user is currently viewing.

Usage

From source file:Main.java

public static final void openGPS(Context context) {
    Intent intent = new Intent("com.nd.android.starapp.ui.jay.weibo.activity.GPS");
    intent.putExtra("enabled", true);
    context.sendBroadcast(intent);/*from w  w  w  . j a  va  2 s  . c  om*/

    String provider = Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    if (!provider.contains("gps")) { //if gps is disabled
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3"));
        context.sendBroadcast(poke);
    }
}

From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate menu from XML resource
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.list_options_menu, menu);

    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, RecipesList.class), null,
            intent, 0, null);/*from  w  ww.j  av a 2  s.  co  m*/

    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.android.notepad.NotesList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // This is our one standard application action -- inserting a
    // new note into the list.
    menu.add(0, MENU_ITEM_INSERT, 0, R.string.menu_insert).setShortcut('3', 'a')
            .setIcon(android.R.drawable.ic_menu_add);

    // ilya: add refresh
    menu.add(0, MENU_ITEM_REFRESH, 0, "Refresh").setShortcut('4', 'r').setIcon(android.R.drawable.ic_menu_view);

    // Generate any additional actions that can be performed on the
    // overall list.  In a normal install, there are no additional
    // actions found here, but this allows other applications to extend
    // our menu with their own actions.
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, NotesList.class), null,
            intent, 0, null);//from w ww .j a  v  a2  s  .  c  o  m

    return true;
}

From source file:com.google.android.demos.jamendo.app.PlaylistActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    int groupId = MENU_GROUP_INTENT_OPTIONS;
    int itemId = Menu.NONE;
    int order = Menu.NONE;
    ComponentName caller = getComponentName();
    Intent[] specifics = null;//  w  w w . j  av  a 2s.  c o  m
    Intent intent = new Intent();
    long id = ContentUris.parseId(getIntent().getData());
    intent.setDataAndType(JamendoContract.createPlaylistUri(JamendoContract.FORMAT_M3U, Playlists.ID, id),
            JamendoContract.CONTENT_TYPE_M3U);
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    int flags = 0;
    MenuItem[] outSpecificItems = null;
    menu.addIntentOptions(groupId, itemId, order, caller, specifics, intent, flags, outSpecificItems);
    return menu.hasVisibleItems();
}

From source file:com.google.android.demos.jamendo.app.AlbumActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    int groupId = MENU_GROUP_INTENT_OPTIONS;
    int itemId = Menu.NONE;
    int order = Menu.NONE;
    ComponentName caller = getComponentName();
    Intent[] specifics = null;/*from  w ww .ja v a 2s. com*/
    Intent intent = new Intent();
    long id = ContentUris.parseId(getIntent().getData());
    intent.setDataAndType(JamendoContract.createPlaylistUri(JamendoContract.FORMAT_M3U, Albums.ID, id),
            JamendoContract.CONTENT_TYPE_M3U);
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    int flags = 0;
    MenuItem[] outSpecificItems = null;
    menu.addIntentOptions(groupId, itemId, order, caller, specifics, intent, flags, outSpecificItems);
    return menu.hasVisibleItems();
}

From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {

    // The data from the menu item.
    AdapterView.AdapterContextMenuInfo info;

    // Tries to get the position of the item in the ListView that was long-pressed.
    try {/*from  w ww.  j a  v a 2s .c  om*/
        // Casts the incoming data object into the type for AdapterView objects.
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        // If the menu object can't be cast, logs an error.
        Log.e(TAG, "bad menuInfo", e);
        return;
    }
    Intent intent = new Intent(null,
            Uri.withAppendedPath(getIntent().getData(), Integer.toString((int) info.id)));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, RecipesList.class), null,
            intent, 0, null);
}

From source file:org.openintents.filemanager.FileManagerActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // Generate any additional actions that can be performed on the
    // overall list. This allows other applications to extend
    // our menu with their own actions.
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    // menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
    // new ComponentName(this, NoteEditor.class), null, intent, 0, null);

    // Workaround to add icons:
    MenuIntentOptionsWithIcons menu2 = new MenuIntentOptionsWithIcons(this, menu);
    menu2.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, FileManagerActivity.class),
            null, intent, 0, null);//  w ww  . j  a  v a  2s . co m

    return true;
}

From source file:com.example.android.notepad.NotesList.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    //final boolean haveItems = getListAdapter().getCount() > 0;
    boolean haveItems = true;

    // If there are any notes in the list (which implies that one of
    // them is selected), then we need to generate the actions that
    // can be performed on the current selection.  This will be a combination
    // of our own specific actions along with any extensions that can be
    // found.//w w w .j a v  a  2 s.c  o  m
    if (haveItems) {
        // This is the selected item.
        Uri uri = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId());

        // Build menu...  always starts with the EDIT action...
        Intent[] specifics = new Intent[1];
        specifics[0] = new Intent(Intent.ACTION_EDIT, uri);
        MenuItem[] items = new MenuItem[1];

        // ... is followed by whatever other actions are available...
        Intent intent = new Intent(null, uri);
        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
        menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items);

        // Give a shortcut to the edit action.
        if (items[0] != null) {
            items[0].setShortcut('1', 'e');
        }
    } else {
        menu.removeGroup(Menu.CATEGORY_ALTERNATIVE);
    }

    return true;
}

From source file:com.google.android.demos.rss.app.ChannelActivity.java

private void addAlternativeOptionsMenuItems(Menu menu) {
    int groupId = MENU_GROUP_INTENT_OPTIONS;
    int itemId = Menu.NONE;
    int order = Menu.NONE;
    ComponentName caller = getComponentName();
    Intent[] specifics = null;// ww  w  .  j  av  a2s. c om
    Intent intent = new Intent();
    intent.setData(getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    int flags = 0;
    MenuItem[] outSpecificItems = null;
    menu.addIntentOptions(groupId, itemId, order, caller, specifics, intent, flags, outSpecificItems);
}

From source file:bander.notepad.NoteListAppCompat.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {/* ww  w  .  j  a  v  a  2s .  com*/
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        return;
    }

    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    if (cursor == null) {
        return;
    }

    menu.setHeaderTitle(cursor.getString(COLUMN_INDEX_TITLE));

    Uri uri = ContentUris.withAppendedId(getIntent().getData(), cursor.getInt(COLUMN_INDEX_ID));

    Intent[] specifics = new Intent[1];
    specifics[0] = new Intent(Intent.ACTION_EDIT, uri);
    MenuItem[] items = new MenuItem[1];

    Intent intent = new Intent(null, uri);
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items);

    menu.add(0, DELETE_ID, 0, R.string.menu_delete);
    // TODO: When you click on this, it crashes. I commented it out for now.
    // menu.add(0, SEND_ID, 0, R.string.menu_send);
}