热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android在launcher中创建实时文件夹

nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd
最近看了launcher方面的知识。在launcher中,选择文件夹选项后,选择“大明通讯录”就在主界面的launcher中创建了个实时文件夹,能调出联系人的姓名来,然后我们可以对其进行处理,点击进入手机号码的内容,然后可以打电话操作等等其他的操作!说明一下:实时文件夹显示有两种方式,一种是列表形式:DISPLAY_MODE_LIST。令一种是宫格的形式:DISPLAY_MODE_GRID。别忘了在Manifest.xml中注册一下:        
 
  1. <strong><span style="font-size:18px;">            <intent-filter>  
  2.                 <action Android:name="android.intent.action.CREATE_LIVE_FOLDER"/>  
  3.                 <category android:name="android.intent.category.DEFAULT"/>  
  4.             intent-filter>  
  5. span>strong>   

   下面看效果图:

 

                     长按主菜单屏幕弹出这个对话框:                                  点击大明通讯录选项:

                                                               

 

                               主界面多了个通讯录的实时文件夹:                          以list形式显示通讯录的内容:

                                                                

 

                                  以grid形式显示通讯录的内容:

                                 

 

 

下面看代码:TempFileWidget程序: 

一、在com.cn.daming的包下面的TempFileWidgetMainActivity.java类中的代码:

  1. >package com.cn.daming;  
  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.ContactsContract;  
  8. import android.provider.LiveFolders;  
  9. import android.widget.Toast;  
  10.   
  11. public class TempFileWidgetMainActivity extends Activity {  
  12.     /** Called when the activity is first created. */  
  13.     @Override  
  14.     public void onCreate(Bundle savedInstanceState) {  
  15.         super.onCreate(savedInstanceState);  
  16.         //charge the floder is refresh floder or not   
  17.         if(getIntent().getAction().equals(LiveFolders.ACTION_CREATE_LIVE_FOLDER)){  
  18.             Intent mIntent = new Intent();  
  19.             mIntent.setData(Uri.parse("content://contacts/live_folders/people"));  
  20.             new Intent(Intent.ACTION_VIEW,ContactsContract.Contacts.CONTENT_URI);  
  21.             mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, "通讯录");  
  22.             mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,  
  23.                     Intent.ShortcutIconResource.fromContext(this, R.drawable.contacts));  
  24.             //list mode   
  25.             mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);  
  26.             //grid mode   
  27. //          mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_GRID);   
  28.             setResult(RESULT_OK, mIntent);  
  29.         }else{  
  30.             setResult(RESULT_CANCELED);  
  31.         }  
  32.         finish();  
  33.     }  
  34. }  

二、在AndroidManifest.xml中的代码:

  1. xml version="1.0" encoding="utf-8"?>  
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  3.       package="com.cn.daming"  
  4.       android:versionCode="1"  
  5.       android:versionName="1.0">  
  6.     <uses-sdk android:minSdkVersion="8" />  
  7.   
  8.     <application android:icon="@drawable/contacts" android:label="@string/app_name">  
  9.         <activity android:name=".TempFileWidgetMainActivity"  
  10.                   android:label="@string/app_name">  
  11.               
  12.             <intent-filter>  
  13.                 <action android:name="android.intent.action.CREATE_LIVE_FOLDER"/>  
  14.                 <category android:name="android.intent.category.DEFAULT"/>  
  15.             intent-filter>  
  16.         activity>  
  17.   
  18.     application>  
  19. manifest>  

三、values包下string中的代码:

  1. xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string name="hello">Hello World, TempFileWidgetMainActivity!string>  
  4.     <string name="app_name">大明通讯录string>  
  5. resources>  

推荐阅读
author-avatar
一恒谢永泰_661
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有