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

本文介绍了一种Android平台上的实时文件夹应用实现方法,详细展示了如何利用系统自带的ContentProvider来创建并配置实时文件夹,使其能够显示联系人数据。

    实时文件夹是一种用来显示由某个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>   

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值