桌面快捷方式和桌面LiveFolder
// to create live folder on "home" screen
if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equalsIgnoreCase(getIntent().getAction())) {// getIntent().getAction() can be null Intent intent = new Intent(); Uri LIVE_FOLDER_URI = Uri.parse("content://contacts/live_folders/people"); intent.setData(LIVE_FOLDER_URI); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, new Intent( Intent.ACTION_VIEW, Contacts.People.CONTENT_URI)); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, "allnamefolder"); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON, Intent.ShortcutIconResource .fromContext(this, R.drawable.krec)); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_GRID); this.setResult(RESULT_OK, intent); } else { this.setResult(Activity.RESULT_CANCELED); }
Intent toPrint = new Intent(this, anSimplePrint.class); Intent addShortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "SP"); addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, toPrint); addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(this, R.drawable.ksig));
<intent-filter><action android:name="android.intent.action.CREATE_SHORTCUT" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter><intent-filter><action android:name="android.intent.action.CREATE_LIVE_FOLDER" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter><uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"></uses-permission>
public class ContactsLiveFolders { public static class StarredContacts extends Activity { public static final Uri CONTENT_URI = Uri.parse("content://contacts/live_folders/favorites"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String action = intent.getAction(); if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) { setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI, getString(R.string.liveFolder_favorites_label), R.drawable.ic_launcher_folder_live_contacts_starred)); } else { setResult(RESULT_CANCELED); } finish(); } } public static class PhoneContacts extends Activity { public static final Uri CONTENT_URI = Uri.parse("content://contacts/live_folders/people_with_phones"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String action = intent.getAction(); if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) { setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI, getString(R.string.liveFolder_phones_label), R.drawable.ic_launcher_folder_live_contacts_phone)); } else { setResult(RESULT_CANCELED); } finish(); } } public static class AllContacts extends Activity { public static final Uri CONTENT_URI = Uri.parse("content://contacts/live_folders/people"); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent intent = getIntent(); final String action = intent.getAction(); if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) { setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI, getString(R.string.liveFolder_all_label), R.drawable.ic_launcher_folder_live_contacts)); } else { setResult(RESULT_CANCELED); } finish(); } } private static Intent createLiveFolder(Context context, Uri uri, String name, int icon) { final Intent intent = new Intent(); intent.setData(uri); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI)); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON, Intent.ShortcutIconResource.fromContext(context, icon)); intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST); return intent; }}
intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI));这个在用的时候。 如果你用的uri读出来没有一个叫name的表项,那这个ACTION_VIEW会失败,所以需要有个叫name的,作为livefolder显示出来的东西。比如系统的contactsprovider 里面 大概3790行 case LIVE_FOLDERS_CONTACTS_GROUP_NAME: qb.setTables(mDbHelper.getContactView()); qb.setProjectionMap(sLiveFoldersProjectionMap); qb.appendWhere(CONTACTS_IN_GROUP_SELECT); selectionArgs = insertSelectionArg(selectionArgs, uri.getLastPathSegment()); break;这里qb.setProjectionMap(sLiveFoldersProjectionMap); 就是把有一个项作为name显示//contactsProvider2.java line 854 sLiveFoldersProjectionMap = new HashMap<String, String>(); sLiveFoldersProjectionMap.put(LiveFolders._ID, Contacts._ID + " AS " + LiveFolders._ID); sLiveFoldersProjectionMap.put(LiveFolders.NAME, Contacts.DISPLAY_NAME + " AS " + LiveFolders.NAME);