歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android 在launcher中創建實時文件夾

Android 在launcher中創建實時文件夾

日期:2017/3/1 11:11:59   编辑:Linux編程
最近看了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. <span style="font-size:13px;color:#000000;">package com.cn.daming;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.provider.ContactsContract;
  7. import android.provider.LiveFolders;
  8. import android.widget.Toast;
  9. public class TempFileWidgetMainActivity extends Activity {
  10. /** Called when the activity is first created. */
  11. @Override
  12. public void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. //charge the floder is refresh floder or not
  15. if(getIntent().getAction().equals(LiveFolders.ACTION_CREATE_LIVE_FOLDER)){
  16. Intent mIntent = new Intent();
  17. mIntent.setData(Uri.parse("content://contacts/live_folders/people"));
  18. new Intent(Intent.ACTION_VIEW,ContactsContract.Contacts.CONTENT_URI);
  19. mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, "通訊錄");
  20. mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
  21. Intent.ShortcutIconResource.fromContext(this, R.drawable.contacts));
  22. //list mode
  23. mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);
  24. //grid mode
  25. // mIntent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_GRID);
  26. setResult(RESULT_OK, mIntent);
  27. }else{
  28. setResult(RESULT_CANCELED);
  29. }
  30. finish();
  31. }
  32. }</span>

二、在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. <application android:icon="@drawable/contacts" android:label="@string/app_name">
  8. <activity android:name=".TempFileWidgetMainActivity"
  9. android:label="@string/app_name">
  10. <!-- add the contacts widget launcher -->
  11. <intent-filter>
  12. <action android:name="android.intent.action.CREATE_LIVE_FOLDER"/>
  13. <category android:name="android.intent.category.DEFAULT"/>
  14. </intent-filter>
  15. </activity>
  16. </application>
  17. </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>
Copyright © Linux教程網 All Rights Reserved