Android 在launcher中创建实时文件夹【安卓进化三十三】

最近看了launcher方面的知识。在launcher中,选择文件夹选项后,选择“大明通讯录”就在主界面的launcher中创建了个实时文件夹,能调出联系人的姓名来,然后我们可以对其进行处理,点击进入手机号码的内容,然后可以打电话操作等等其他的操作!说明一下:实时文件夹显示有两种方式,一种是列表形式:DISPLAY_MODE_LIST。令一种是宫格的形式:DISPLAY_MODE_GRID。别忘了在Manifest.xml中注册一下:

<intent-filter> <action android:name="android.intent.action.CREATE_LIVE_FOLDER"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter>


转载请标明出处:http://blog.youkuaiyun.com/wdaming1986/article/details/6878873

下面看效果图:

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

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

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

下面看代码:TempFileWidget程序:

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

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(); } }

二、在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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值