生活随笔
收集整理的這篇文章主要介紹了
桌面快捷键和桌面livefolder
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?// to create live folder on "home" screen?
Java代碼??
if?(LiveFolders.ACTION_CREATE_LIVE_FOLDER.equalsIgnoreCase(getIntent().getAction()))?{ ??tent().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); ??}?? [java]?view plaincopy
if?(LiveFolders.ACTION_CREATE_LIVE_FOLDER.equalsIgnoreCase(getIntent().getAction()))?{??tent().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);??}??
// to create shortcut on "home" screen?
// toPrint is a very simple apk.?
Java代碼??
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));?? [java]?view plaincopy
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));??
//remember to fix manifest file?
// add .?
Java代碼??
????????<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>?? [java]?view plaincopy
????????<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>??
///?
// 系統(tǒng)的contacts 在桌面livefolder添加快捷方式的代碼如下。想要在livefolder中添加// 其他app的快捷方式,也可以依法炮制?
Java代碼??
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; ??????} ??}?? [java]?view plaincopy
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;??????}??}??
?
//?
Java代碼??
????????intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, ??????????????????new?Intent(Intent.ACTION_VIEW,?Contacts.CONTENT_URI)); ??這個(gè)在用的時(shí)候。?如果你用的uri讀出來(lái)沒有一個(gè)叫name的表項(xiàng), ??那這個(gè)ACTION_VIEW會(huì)失敗,所以需要有個(gè)叫name的,作為livefolder顯示出來(lái)的東西。 ????比如系統(tǒng)的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);?就是把有一個(gè)項(xiàng)作為name顯示 ???????????sLiveFoldersProjectionMap?=?new?HashMap<String,?String>(); ??????????sLiveFoldersProjectionMap.put(LiveFolders._ID, ??????????????????Contacts._ID?+?"?AS?"?+?LiveFolders._ID); ??????????sLiveFoldersProjectionMap.put(LiveFolders.NAME, ??????????????????Contacts.DISPLAY_NAME?+?"?AS?"?+?LiveFolders.NAME);?? [java]?view plaincopy
????????intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT,??????????????????new?Intent(Intent.ACTION_VIEW,?Contacts.CONTENT_URI));??這個(gè)在用的時(shí)候。?如果你用的uri讀出來(lái)沒有一個(gè)叫name的表項(xiàng),??那這個(gè)ACTION_VIEW會(huì)失敗,所以需要有個(gè)叫name的,作為livefolder顯示出來(lái)的東西。????比如系統(tǒng)的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);?就是把有一個(gè)項(xiàng)作為name顯示???????????sLiveFoldersProjectionMap?=?new?HashMap<String,?String>();??????????sLiveFoldersProjectionMap.put(LiveFolders._ID,??????????????????Contacts._ID?+?"?AS?"?+?LiveFolders._ID);??????????sLiveFoldersProjectionMap.put(LiveFolders.NAME,??????????????????Contacts.DISPLAY_NAME?+?"?AS?"?+?LiveFolders.NAME);??
自己實(shí)現(xiàn)一contentprovider來(lái)做這個(gè)事情的時(shí)候也需要實(shí)現(xiàn)一個(gè) name作為顯示,?
即在cursor query的時(shí)候加入比如select xxx as name, 在projection里加。?
說(shuō)不清了。。。?
//一般還是不要自己造contentprovider了。。 系統(tǒng)的差不多夠用?
//問(wèn)題是怎么在系統(tǒng)里找到所有的uri? 嘿嘿。我不會(huì)- -?
這里轉(zhuǎn)個(gè)大大的博克?
http://kuikui.iteye.com/blog/318627?
剛起步的時(shí)候經(jīng)常困擾我們的是一些本來(lái)容易解決的問(wèn)題,往往我們會(huì)花掉很大的力氣去找解決的辦法,最后才知道原來(lái)這么簡(jiǎn)單,這就是英文世界造成的。?
Intent在 Android應(yīng)用開發(fā)中,占有很大的分量,關(guān)于Intent在Android中的作用在網(wǎng)絡(luò)上已經(jīng)有很多資料了,這里不再累贅,本人喜歡直來(lái)直去。在網(wǎng)上看到很多關(guān)于Intent的資料,說(shuō)那么多,你也許還是一頭霧水,到底如何使用Intent呢?這里總結(jié)一些重用的Intent使用,僅供參考。?
下面直接給我學(xué)習(xí)的實(shí)例片段。?
1,掉web瀏覽器?
Uri myBlogUri = Uri.parse("http://kuikui.iteye.com");?
returnIt = new Intent(Intent.ACTION_VIEW, myBlogUri);?
2,地圖?
Uri mapUri = Uri.parse("geo:38.899533,-77.036476");?
returnIt = new Intent(Intent.ACTION_VIEW, mapUri);?
3,調(diào)撥打電話界面?
Uri telUri = Uri.parse("tel:100861");?
returnIt = new Intent(Intent.ACTION_DIAL, telUri);?
4,直接撥打電話?
Uri callUri = Uri.parse("tel:100861");?
returnIt = new Intent(Intent.ACTION_CALL, callUri);?
5,卸載?
Uri uninstallUri = Uri.fromParts("package", "xxx", null);?
returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);?
6,安裝?
Uri installUri = Uri.fromParts("package", "xxx", null);?
returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);?
7,播放?
Uri playUri = Uri.parse("file:///sdcard/download/everything.mp3");?
returnIt = new Intent(Intent.ACTION_VIEW, playUri);?
8,掉用發(fā)郵件?
Uri emailUri = Uri.parse("mailto:shenrenkui@gmail.com");?
returnIt = new Intent(Intent.ACTION_SENDTO, emailUri);?
9,發(fā)郵件?
returnIt = new Intent(Intent.ACTION_SEND);?
String[] tos = { "shenrenkui@gmail.com" };?
String[] ccs = { "shenrenkui@gmail.com" };?
returnIt.putExtra(Intent.EXTRA_EMAIL, tos);?
returnIt.putExtra(Intent.EXTRA_CC, ccs);?
returnIt.putExtra(Intent.EXTRA_TEXT, "body");?
returnIt.putExtra(Intent.EXTRA_SUBJECT, "subject");?
returnIt.setType("message/rfc882");?
Intent.createChooser(returnIt, "Choose Email Client");?
10,發(fā)短信?
Uri smsUri = Uri.parse("tel:100861");?
returnIt = new Intent(Intent.ACTION_VIEW, smsUri);?
returnIt.putExtra("sms_body", "shenrenkui");?
returnIt.setType("vnd.android-dir/mms-sms");?
11,直接發(fā)郵件?
Uri smsToUri = Uri.parse("smsto://100861");?
returnIt = new Intent(Intent.ACTION_SENDTO, smsToUri);?
returnIt.putExtra("sms_body", "shenrenkui");?
12,發(fā)彩信?
Uri mmsUri = Uri.parse("content://media/external/images/media/23");?
returnIt = new Intent(Intent.ACTION_SEND);?
returnIt.putExtra("sms_body", "shenrenkui");?
returnIt.putExtra(Intent.EXTRA_STREAM, mmsUri);?
returnIt.setType("image/png");?
用獲取到的Intent直接調(diào)用startActivity(returnIt)就ok了
轉(zhuǎn)載于:https://www.cnblogs.com/greywolf/archive/2012/12/24/2831344.html
總結(jié)
以上是生活随笔為你收集整理的桌面快捷键和桌面livefolder的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。