Android 在launcher中创建实时文件夹
Android 在launcher中创建实时文件夹
最近看了launcher方面的知识。在launcher中,选择文件夹选项后,选择“大明通讯录”就在主界面的launcher中创建了个实时文件夹,能调出联系人的姓名来,然后我们可以对其进行处理,点击进入手机号码的内容,然后可以打电话操作等等其他的操作!说明一下:实时文件夹显示有两种方式,一种是列表形式:DISPLAY_MODE_LIST。令一种是宫格的形式:DISPLAY_MODE_GRID。别忘了在Manifest.xml中注册一下:- <strong><span style="font-size:18px;"> <intent-filter>
- <action Android:name="android.intent.action.CREATE_LIVE_FOLDER"/>
- <category android:name="android.intent.category.DEFAULT"/>
- </intent-filter>
- </span></strong>
下面看效果图:
长按主菜单屏幕弹出这个对话框: 点击大明通讯录选项:
主界面多了个通讯录的实时文件夹: 以list形式显示通讯录的内容:
以grid形式显示通讯录的内容:
下面看代码:TempFileWidget程序:
一、在com.cn.daming的包下面的TempFileWidgetMainActivity.java类中的代码:
- <span style="font-size:13px;color:#000000;">package com.cn.daming;
- import android.app.Activity;
- import android.content.Intent;
- import android.net.Uri;
- import android.os.Bundle;
- import android.provider.ContactsContract;
- import android.provider.LiveFolders;
- import android.widget.Toast;
- public class TempFileWidgetMainActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //charge the floder is refresh floder or not
- if(getIntent().getAction().equals(LiveFolders.ACTION_CREATE_LIVE_FOLDER)){
- Intent mIntent = new Intent();
- mIntent.setData(Uri.parse("content://contacts/live_folders/people"));
- new Intent(Intent.ACTION_VIEW,ContactsContract.Contacts.CONTENT_URI);
- mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, "通讯录");
- mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
- Intent.ShortcutIconResource.fromContext(this, R.drawable.contacts));
- //list mode
- mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);
- //grid mode
- // mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_GRID);
- setResult(RESULT_OK, mIntent);
- }else{
- setResult(RESULT_CANCELED);
- }
- finish();
- }
- }</span>
二、在AndroidManifest.xml中的代码:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.cn.daming"
- android:versionCode="1"
- android:versionName="1.0">
- <uses-sdk android:minSdkVersion="8" />
- <application android:icon="@drawable/contacts" android:label="@string/app_name">
- <activity android:name=".TempFileWidgetMainActivity"
- android:label="@string/app_name">
- <!-- add the contacts widget launcher -->
- <intent-filter>
- <action android:name="android.intent.action.CREATE_LIVE_FOLDER"/>
- <category android:name="android.intent.category.DEFAULT"/>
- </intent-filter>
- </activity>
- </application>
- </manifest>
三、values包下string中的代码:
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="hello">Hello World, TempFileWidgetMainActivity!</string>
- <string name="app_name">大明通讯录</string>
- </resources>
评论暂时关闭