Android Real-time folder creation method _android

Source: Internet
Author: User

This example describes the Android real-time folder creation method. Share to everyone for your reference. Specifically as follows:

A live folder is a desktop component that is used to display data information provided by a contentprovider. To create a live folder, you must have two supports. On the one hand, you define an activity to create a live folder. On the other hand, the contentprovider of the specified data information URI must support queries for live folders. In this section, you will describe how to create a live folder for your application.

Similar to adding a shortcut to a launcher desktop, a list dialog box for a live folder pops up when a user selects a live folder after a long press on the desktop. If we want to add the activity within our application to this list, we just need to add an action to the android.intent.action.CREATE_LIVE_ when the activity is registered. The Intentfilter of the folder. In this activity that creates a live folder, we store the information in the Live folder in the form of additional information in a intent object and return it to the launcher application to perform the addition via result. The following table lists the key values and data types for attachment information related to live folder information.

Key values and data types for real-time folders

There are two kinds of display_mode, the value is 1 o'clock, in the form of grid (GRID) to display the expanded real-time folder content, when 2 is in the form of lists (list) display. In addition to the additional information above, the URI to be queried for data is stored in the intent object in the form of. Since contacts's ContentProvider has already implemented support for real-time folders, let's use the program to create a live folder for all the contacts as an example of 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.onc
    Reate (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.conta Cts.
      Content_uri)); Intent.putextra (Livefolders.extra_live_folder_name, "telephone book"); The title of the shortcut Intent.putextra (Livefolders.extra_live_folder_icon, Intent.ShortcutIconResource.fromContext) (this , r.drawable.png1));//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 ();

 }
}

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>

Run results

I hope this article will help you with your Android program.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.