public final class

LiveFolders

extends Object
implements BaseColumns
java.lang.Object
   ↳android.provider.LiveFolders

Class Overview

A LiveFolder is a special folder whose content is provided by a ContentProvider. To create a live folder, two components are required:

Lifecycle

When a user wants to create a live folder, the system looks for all activities with the intent filter action ACTION_CREATE_LIVE_FOLDER and presents the list to the user. When the user chooses one of the activities, the activity is invoked with the ACTION_CREATE_LIVE_FOLDER action. The activity then creates the live folder and passes it back to the system by setting it as an activity result. The live folder is described by a content provider URI, a name, an icon and a display mode. Finally, when the user opens the live folder, the system queries the content provider to retrieve the folder's content.

Setting up the live folder activity

The following code sample shows how to write an activity that creates a live folder:

 public static class MyLiveFolder extends Activity {
     public static final Uri CONTENT_URI = Uri.parse("content://my.app/live");

     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         final Intent intent = getIntent();
         final String action = intent.getAction();

         if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
             setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI, "My LiveFolder",
                     R.drawable.ic_launcher_contacts_phones));
         } else {
             setResult(RESULT_CANCELED);
         }

         finish();
     }

     private static Intent createLiveFolder(Context context, Uri uri, String name,
             int icon) {

         final Intent intent = new Intent();

         intent.setData(uri);
         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name);
         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
                 Intent.ShortcutIconResource.fromContext(context, icon));
         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);

         return intent;
     }
 }
 

The live folder is described by an Intent as follows:

ComponentTypeDescriptionRequired
URIURIThe ContentProvider URIYes
EXTRA_LIVE_FOLDER_NAMEExtra StringThe name of the live folderYes
EXTRA_LIVE_FOLDER_ICONExtra Intent.ShortcutIconResourceThe icon of the live folderYes
EXTRA_LIVE_FOLDER_DISPLAY_MODEExtra intThe display mode of the live folder. The value must be either DISPLAY_MODE_GRID or DISPLAY_MODE_LIST.Yes
EXTRA_LIVE_FOLDER_BASE_INTENTExtra IntentWhen the user clicks an item inside a live folder, the system will either fire the intent associated with that item or, if present, the live folder's base intent with the id of the item appended to the base intent's URI.No

Setting up the content provider

The live folder's content provider must, upon query, return a Cursor whose columns match the following names:

ColumnTypeDescriptionRequired
NAMEStringThe name of the itemYes
DESCRIPTIONStringThe description of the item. The description is ignored when the live folder's display mode is DISPLAY_MODE_GRID.No
INTENTIntentThe intent to fire when the item is clicked. Ignored when the live folder defines a base intent.No
ICON_BITMAPBitmapThe icon for the item. When this column value is not null, the values for the columns ICON_PACKAGE and ICON_RESOURCE must be null.No
ICON_PACKAGEStringThe package of the item's icon. When this value is not null, the value for the column ICON_RESOURCE must be specified and the value for the column ICON_BITMAP must be null.No
ICON_RESOURCEStringThe resource name of the item's icon. When this value is not null, the value for the column ICON_PACKAGE must be specified and the value for the column ICON_BITMAP must be null.No

Summary

Constants
StringACTION_CREATE_LIVE_FOLDERActivity Action: Creates a live folder.
StringDESCRIPTION

Content provider column.

intDISPLAY_MODE_GRIDDisplays a live folder's content in a grid.
intDISPLAY_MODE_LISTDisplays a live folder's content in a list.
StringEXTRA_LIVE_FOLDER_BASE_INTENTThe name of the extra used to define the base Intent of a live folder.
StringEXTRA_LIVE_FOLDER_DISPLAY_MODEThe name of the extra used to define the display mode of a live folder.
StringEXTRA_LIVE_FOLDER_ICONThe name of the extra used to define the icon of a live folder.
StringEXTRA_LIVE_FOLDER_NAMEThe name of the extra used to define the name of a live folder.
StringICON_BITMAP

Content provider column.

StringICON_PACKAGE

Content provider column.

StringICON_RESOURCE

Content provider column.

StringINTENT

Content provider column.

StringNAME

Content provider column.

[Expand]
Inherited Constants
From interface android.provider.BaseColumns
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String ACTION_CREATE_LIVE_FOLDER

Since: API Level 3

Activity Action: Creates a live folder.

Input: Nothing.

Output: An Intent representing the live folder. The intent must contain four extras: EXTRA_LIVE_FOLDER_NAME (value: String), EXTRA_LIVE_FOLDER_ICON (value: ShortcutIconResource), EXTRA_LIVE_FOLDER_URI (value: String) and EXTRA_LIVE_FOLDER_DISPLAY_MODE (value: int). The Intent can optionnally contain EXTRA_LIVE_FOLDER_BASE_INTENT (value: Intent).

Constant Value: "android.intent.action.CREATE_LIVE_FOLDER"

public static final String DESCRIPTION

Since: API Level 3

Content provider column.

Description of the live folder item. This value is ignored if the live folder's display mode is DISPLAY_MODE_GRID.

Optional.

Type: String.

Constant Value: "description"

public static final int DISPLAY_MODE_GRID

Since: API Level 3

Displays a live folder's content in a grid.

Constant Value: 1 (0x00000001)

public static final int DISPLAY_MODE_LIST

Since: API Level 3

Displays a live folder's content in a list.

Constant Value: 2 (0x00000002)

public static final String EXTRA_LIVE_FOLDER_BASE_INTENT

Since: API Level 3

The name of the extra used to define the base Intent of a live folder.

Constant Value: "android.intent.extra.livefolder.BASE_INTENT"

public static final String EXTRA_LIVE_FOLDER_DISPLAY_MODE

Since: API Level 3

The name of the extra used to define the display mode of a live folder.

Constant Value: "android.intent.extra.livefolder.DISPLAY_MODE"

public static final String EXTRA_LIVE_FOLDER_ICON

Since: API Level 3

The name of the extra used to define the icon of a live folder.

Constant Value: "android.intent.extra.livefolder.ICON"

public static final String EXTRA_LIVE_FOLDER_NAME

Since: API Level 3

The name of the extra used to define the name of a live folder.

Constant Value: "android.intent.extra.livefolder.NAME"

public static final String ICON_BITMAP

Since: API Level 3

Content provider column.

Icon of the live folder item, as a custom bitmap.

Optional.

Type: Bitmap.

Constant Value: "icon_bitmap"

public static final String ICON_PACKAGE

Since: API Level 3

Content provider column.

Package where to find the icon of the live folder item. This value can be obtained easily using fromContext(android.content.Context, int).

Optional.

Type: String.

Constant Value: "icon_package"

public static final String ICON_RESOURCE

Since: API Level 3

Content provider column.

Resource name of the live folder item. This value can be obtained easily using fromContext(android.content.Context, int).

Optional.

Type: String.

Constant Value: "icon_resource"

public static final String INTENT

Since: API Level 3

Content provider column.

Intent of the live folder item.

Optional if the live folder has a base intent.

Type: Intent.

Constant Value: "intent"

public static final String NAME

Since: API Level 3

Content provider column.

Name of the live folder item.

Required.

Type: String.

Constant Value: "name"