Android桌面组件开发之实时文件夹(Live_Folders)



 实时文件夹是一种用来显示由某个
ContentProvider提供的数据信息的桌面组件。

有定义就可以知道,必须要定义一个ContentProvider,或者用系统自带的ContentProvider,系统自带的Contacts(联系人)程序已经实现了对实时文件夹的支持(关于如何实现自己的ContentProvider,并支持实时文件夹,下次笔记总结)。

MyAllContacts.java文件代码:

Code:

1.     package com.myAllContacts.test;  

2.       

3.     import android.app.Activity;  

4.     import android.content.Intent;  

5.     import android.net.Uri;  

6.     import android.os.Bundle;  

7.     import android.provider.Contacts;  

8.     import android.provider.LiveFolders;  

9.       

10.  public class MyAllContacts extends Activity {  

11.      public static final Uri LIVE_FOLDER_URI = Uri  

12.              .parse("content://contacts/live_folders/people");  

13.    

14.      /** Called when the activity is first created. */  

15.      @Override  

16.      public void onCreate(Bundle savedInstanceState) {  

17.          super.onCreate(savedInstanceState);  

18.    

19.          /*if (getIntent().getAction().equals( 

20.           * 我认为这里无需判断,既然已经在AndroidMainfest.xml文件里配置了,如若能打开这个Activity 

21.           * 证明这个判断就通过,这里就多此一举。 

22.                  LiveFolders.ACTION_CREATE_LIVE_FOLDER)) {*/  

23.              Intent intent = new Intent();  

24.              intent.setData(LIVE_FOLDER_URI);  

25.              intent  

26.                      .putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME,  

27.                              "MyAllContacts");  

28.              intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT,  

29.                      new Intent(Intent.ACTION_VIEW, Contacts.People.CONTENT_URI));  

30.              intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,  

31.                      Intent.ShortcutIconResource.fromContext(this,  

32.                              R.drawable.my_icon));  

33.              intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,  

34.                      LiveFolders.DISPLAY_MODE_LIST);  

35.              setResult(RESULT_OK, intent);  

36.          /*} else {*/  

37.              //setResult(RESULT_CANCELED);  

38.          //}  

39.    

40.          finish();  

41.    

42.      }  

43.  }  

AndroidManifest.xml

Code:

1.     <?xml version="1.0" encoding="utf-8"?>  

2.     <manifest xmlns:android="http://schemas.android.com/apk/res/android"  

3.           package="com.myAllContacts.test"  

4.           android:versionCode="1"  

5.           android:versionName="1.0">  

6.         <application android:icon="@drawable/icon" android:label="@string/app_name">  

7.             <activity android:name=".MyAllContacts"  

8.                       android:label="@string/app_name">  

9.                 <intent-filter>  

10.                  <action android:name="android.intent.action.CREATE_LIVE_FOLDER" />  

11.                  <category android:name="android.intent.category.DEFAULT" />  

12.              </intent-filter>  

13.          </activity>  

14.    

15.      </application>  

16.      <uses-sdk android:minSdkVersion="8" />  

17.    

18.  </manifest>   

 

 
Android桌面组件开发之实时文件夹(Live_Folders)