实时文件夹是一种用来显示由某个ContentProvider提供的数据信息的桌面组件。
有定义就可以知道,必须要定义一个ContentProvider,或者用系统自带的ContentProvider,系统自带的Contacts(联系人)程序已经实现了对实时文件夹的支持(关于如何实现自己的ContentProvider,并支持实时文件夹,下次笔记总结)。
MyAllContacts.java文件代码:
- package com.myAllContacts.test;
- import android.app.Activity;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.provider.Contacts;
- import android.provider.LiveFolders;
- public class MyAllContacts extends Activity {
- public static final Uri LIVE_FOLDER_URI = Uri
- .parse("content://contacts/live_folders/people");
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- /*if (getIntent().getAction().equals(
- * 我认为这里无需判断,既然已经在AndroidMainfest.xml文件里配置了,如若能打开这个Activity,
- * 证明这个判断就通过,这里就多此一举。
- LiveFolders.ACTION_CREATE_LIVE_FOLDER)) {*/
- Intent intent = new Intent();
- intent.setData(LIVE_FOLDER_URI);
- intent
- .putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME,
- "MyAllContacts");
- intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT,
- new Intent(Intent.ACTION_VIEW, Contacts.People.CONTENT_URI));
- intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
- Intent.ShortcutIconResource.fromContext(this,
- R.drawable.my_icon));
- intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
- LiveFolders.DISPLAY_MODE_LIST);
- setResult(RESULT_OK, intent);
- /*} else {*/
- //setResult(RESULT_CANCELED);
- //}
- finish();
- }
- }
AndroidManifest.xml
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.myAllContacts.test"
- android:versionCode="1"
- android:versionName="1.0">
- <application android:icon="@drawable/icon" android:label="@string/app_name">
- <activity android:name=".MyAllContacts"
- android:label="@string/app_name">
- <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="8" />
- </manifest>