Home>

A live folder is a desktop component used to display data information provided by a contentprovider.To create a live folder,There must be support on two fronts.On the one hand,To define an activity to create a live folder. On the other hand,The contentprovider of the specified data information uri must support the query of the real-time folder.In this section, you will learn how to create a live folder for your application.

Similar to adding a shortcut to the launcher's desktop,A long-press on the desktop and selecting a live folder will pop up a list of available live folders.If we want to add the activity in our application to this list,Also just add an intent filter with action android.intent.action.create_live_folder when the activity is registered. In this activity that creates a real-time folder, we need to store the information of the real-time folder in an intent object in the form of additional information.And return to the launcher application through result to perform the addition.The following table lists the key values ​​and data types of attachment information related to live folder information.

Keys and data types of live folders

There are two types of display_mode. When the value is 1, the expanded real-time folder content is displayed in a grid.When it is 2, it is displayed in list form.In addition to the additional information above,For the data to be queried, the URI is stored in the intent object in the form of data.As the contentprovider of contacts has implemented related support for live folders,So let's take the procedure of creating a live folder of 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, "Phonebook");//shortcut title
      intent.putextra (livefolders.extra_live_folder_icon,          intent.shortcuticonresource.fromcontext (this, r.drawable.png1));//The icon of the shortcut
      intent.putextra (livefolders.extra_live_folder_display_mode, livefolders.display_mode_list);//Display model
      setresult (result_ok, intent);
    }
    else {
      setresult (result_canceled);
    }
    finish ();
  }
}

Manifest 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">
  <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>

operation result

  • Previous ASPNET food management system production code sharing
  • Next 2 ways to bulk import data in SQL Server database