A Real-time folder is a desktop component used to display data information provided by a ContentProvider. To create a real-time folder, you must have two support options. On the one hand, you need to define an Activity for creating real-time folders. On the other hand, the ContentProvider of the specified data information URI must support real-time folder query. This section describes how to create real-time folders for applications.
Similar to adding a shortcut to the Launcher desktop, you can select a Real-Time folder after you press it on the desktop to display a list of available real-time folders. If you want to add the Activity in your application to this list, you also need to add an IntentFilter with the Action android. intent. action. CREATE_LIVE_FOLDER when registering the Activity. In this Activity that creates a real-time folder, We need to store the Real-Time Folder Information in the form of additional information in an Intent object, and return the Result to the Launcher application for execution and addition. The following table lists the key values and Data Types of the attachment information related to the real-time Folder Information.
Key Value and data type of real-time folders
DISPLAY_MODE has two types. When the value is 1, the expanded real-time folder content is displayed in Grid Format. If the value is 2, the expanded real-time folder content is displayed in List format. In addition to the above additional information, the URI of the Data to be queried is stored in the Intent object in the form of Data. As Contacts ContentProvider has implemented support for real-time folders, the following uses a program to create real-time folders for all Contacts as an example in this section.
TestActivity class
Package com. ljq. activity;
Import android. app. Activity;
Import android. content. Intent;
Import android.net. Uri;
Import android. OS. Bundle;
Import android. provider. ContactsContract;
Import android. provider. LiveFolders;
Public class TestActivity extends Activity {
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
If (getIntent (). getAction (). equals (LiveFolders. ACTION_CREATE_LIVE_FOLDER )){
Intent intent = new Intent ();
Intent. setData (Uri. parse ("content: // contacts/live_folders/people "));
Intent. putExtra (LiveFolders. EXTRA_LIVE_FOLDER_BASE_INTENT,
New Intent (Intent. ACTION_VIEW, ContactsContract. Contacts. CONTENT_URI ));
Intent. putExtra (LiveFolders. EXTRA_LIVE_FOLDER_NAME, "phone book"); // the title of the shortcut
Intent. putExtra (LiveFolders. EXTRA_LIVE_FOLDER_ICON,
Intent. Export cuticonresource. fromContext (this, R.drawable.png 1); // shortcut icon
Intent. putExtra (LiveFolders. EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders. DISPLAY_MODE_LIST); // display model
SetResult (RESULT_ OK, intent );
}
Else {
SetResult (RESULT_CANCELED );
}
Finish ();
}
}
Configuration File
<? Xml version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. ljq. activity" android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">
<Application android: icon = "@ drawable/icon"
Android: label = "@ string/app_name">
<Activity android: name = ". TestActivity"
Android: label = "@ string/app_name">
<! -- Note here -->
<Intent-filter>
<Action android: name = "android. intent. action. CREATE_LIVE_FOLDER"/>
<Category android: name = "android. intent. category. DEFAULT"/>
</Intent-filter>
</Activity>
</Application>
<Uses-sdk android: minSdkVersion = "7"/>
</Manifest>
Running result
1, 2, 3,