<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="king.demo"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
package king.demo;
import android.R.anim;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.Contacts;
import android.provider.Contacts.People;
import android.provider.LiveFolders;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//判斷是否建立即時檔案夾
if(getIntent().getAction().equals(LiveFolders.ACTION_CREATE_LIVE_FOLDER)){
Intent intent = new Intent();
//設定資料地址
intent.setData(Uri.parse("content://contacts/people/")); //連絡人的URI
//設定單擊之後的事件,這裡單擊一個連絡人後,呼叫
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT,
new Intent(Intent.ACTION_CALL, android.provider.Contacts.People.CONTENT_URI));
//設定即時檔案夾的名字
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, "電話本");
//設定實施檔案夾的表徵圖
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
//設定顯示模式為列表
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);
//完成
setResult(RESULT_OK, intent);
}
else
{
setResult(RESULT_CANCELED);
}
finish();
}
}