桌面快捷键和桌面livefolder

 // to create live folder on "home" screen 

Java代码 复制代码 收藏代码
  1. if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equalsIgnoreCase(getIntent().getAction())) {   
  2. tent().getAction() can be null  
  3.     Intent intent = new Intent();   
  4.     Uri LIVE_FOLDER_URI = Uri.parse("content://contacts/live_folders/people");   
  5.     intent.setData(LIVE_FOLDER_URI);   
  6.     intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, new Intent(   
  7.             Intent.ACTION_VIEW, Contacts.People.CONTENT_URI));   
  8.     intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, "allnamefolder");   
  9.     intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON, Intent.ShortcutIconResource   
  10.             .fromContext(this, R.drawable.krec));   
  11.     intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,   
  12.             LiveFolders.DISPLAY_MODE_GRID);   
  13.     this.setResult(RESULT_OK, intent);   
  14.   
  15. else {   
  16.     this.setResult(Activity.RESULT_CANCELED);   
  17. }  
  1. if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equalsIgnoreCase(getIntent().getAction())) {  
  2. tent().getAction() can be null  
  3.     Intent intent = new Intent();  
  4.     Uri LIVE_FOLDER_URI = Uri.parse("content://contacts/live_folders/people");  
  5.     intent.setData(LIVE_FOLDER_URI);  
  6.     intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT, new Intent(  
  7.             Intent.ACTION_VIEW, Contacts.People.CONTENT_URI));  
  8.     intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, "allnamefolder");  
  9.     intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON, Intent.ShortcutIconResource  
  10.             .fromContext(this, R.drawable.krec));  
  11.     intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,  
  12.             LiveFolders.DISPLAY_MODE_GRID);  
  13.     this.setResult(RESULT_OK, intent);  
  14.   
  15. else {  
  16.     this.setResult(Activity.RESULT_CANCELED);  
  17. }  





// to create shortcut on "home" screen 
// toPrint is a very simple apk. 

Java代码 复制代码 收藏代码
  1. Intent toPrint = new Intent(this, anSimplePrint.class);   
  2.   
  3. Intent addShortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");   
  4. addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "SP");   
  5. addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, toPrint);   
  6. addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource   
  7.         .fromContext(this, R.drawable.ksig));  
  1. Intent toPrint = new Intent(this, anSimplePrint.class);  
  2.   
  3. Intent addShortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");  
  4. addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "SP");  
  5. addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, toPrint);  
  6. addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource  
  7.         .fromContext(this, R.drawable.ksig));  


//remember to fix manifest file 
// add . 

Java代码 复制代码 收藏代码
  1.         <intent-filter>   
  2.             <action android:name="android.intent.action.CREATE_SHORTCUT" />   
  3.             <category android:name="android.intent.category.LAUNCHER" />   
  4.         </intent-filter>   
  5.         <intent-filter>   
  6.             <action android:name="android.intent.action.CREATE_LIVE_FOLDER" />   
  7.             <category android:name="android.intent.category.LAUNCHER" />   
  8.         </intent-filter>   
  9.   
  10.   
  11. <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"></uses-permission>  
  1.         <intent-filter>  
  2.             <action android:name="android.intent.action.CREATE_SHORTCUT" />  
  3.             <category android:name="android.intent.category.LAUNCHER" />  
  4.         </intent-filter>  
  5.         <intent-filter>  
  6.             <action android:name="android.intent.action.CREATE_LIVE_FOLDER" />  
  7.             <category android:name="android.intent.category.LAUNCHER" />  
  8.         </intent-filter>  
  9.   
  10.   
  11. <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"></uses-permission>  




/////////////////////////////////////////////////////////////////////////////// 
// 系统的contacts 在桌面livefolder添加快捷方式的代码如下。想要在livefolder中添加// 其他app的快捷方式,也可以依法炮制 

Java代码 复制代码 收藏代码
  1. public class ContactsLiveFolders {   
  2.     public static class StarredContacts extends Activity {   
  3.         public static final Uri CONTENT_URI =   
  4.                 Uri.parse("content://contacts/live_folders/favorites");   
  5.   
  6.         @Override  
  7.         protected void onCreate(Bundle savedInstanceState) {   
  8.             super.onCreate(savedInstanceState);   
  9.   
  10.             final Intent intent = getIntent();   
  11.             final String action = intent.getAction();   
  12.   
  13.             if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {   
  14.                 setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,   
  15.                         getString(R.string.liveFolder_favorites_label),   
  16.                         R.drawable.ic_launcher_folder_live_contacts_starred));   
  17.             } else {   
  18.                 setResult(RESULT_CANCELED);   
  19.             }   
  20.   
  21.             finish();   
  22.         }   
  23.     }   
  24.   
  25.     public static class PhoneContacts extends Activity {   
  26.         public static final Uri CONTENT_URI =   
  27.                 Uri.parse("content://contacts/live_folders/people_with_phones");   
  28.   
  29.         @Override  
  30.         protected void onCreate(Bundle savedInstanceState) {   
  31.             super.onCreate(savedInstanceState);   
  32.   
  33.             final Intent intent = getIntent();   
  34.             final String action = intent.getAction();   
  35.   
  36.             if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {   
  37.                 setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,   
  38.                         getString(R.string.liveFolder_phones_label),   
  39.                         R.drawable.ic_launcher_folder_live_contacts_phone));   
  40.             } else {   
  41.                 setResult(RESULT_CANCELED);   
  42.             }   
  43.   
  44.             finish();   
  45.         }   
  46.     }   
  47.   
  48.     public static class AllContacts extends Activity {   
  49.         public static final Uri CONTENT_URI =   
  50.                 Uri.parse("content://contacts/live_folders/people");   
  51.   
  52.         @Override  
  53.         protected void onCreate(Bundle savedInstanceState) {   
  54.             super.onCreate(savedInstanceState);   
  55.   
  56.             final Intent intent = getIntent();   
  57.             final String action = intent.getAction();   
  58.   
  59.             if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {   
  60.                 setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,   
  61.                         getString(R.string.liveFolder_all_label),   
  62.                         R.drawable.ic_launcher_folder_live_contacts));   
  63.             } else {   
  64.                 setResult(RESULT_CANCELED);   
  65.             }   
  66.   
  67.             finish();   
  68.         }   
  69.     }   
  70.   
  71.     private static Intent createLiveFolder(Context context, Uri uri, String name,   
  72.             int icon) {   
  73.   
  74.         final Intent intent = new Intent();   
  75.   
  76.         intent.setData(uri);   
  77.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT,   
  78.                 new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI));   
  79.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name);   
  80.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,   
  81.                 Intent.ShortcutIconResource.fromContext(context, icon));   
  82.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);   
  83.   
  84.         return intent;   
  85.     }   
  86. }  
  1. public class ContactsLiveFolders {  
  2.     public static class StarredContacts extends Activity {  
  3.         public static final Uri CONTENT_URI =  
  4.                 Uri.parse("content://contacts/live_folders/favorites");  
  5.   
  6.         @Override  
  7.         protected void onCreate(Bundle savedInstanceState) {  
  8.             super.onCreate(savedInstanceState);  
  9.   
  10.             final Intent intent = getIntent();  
  11.             final String action = intent.getAction();  
  12.   
  13.             if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {  
  14.                 setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,  
  15.                         getString(R.string.liveFolder_favorites_label),  
  16.                         R.drawable.ic_launcher_folder_live_contacts_starred));  
  17.             } else {  
  18.                 setResult(RESULT_CANCELED);  
  19.             }  
  20.   
  21.             finish();  
  22.         }  
  23.     }  
  24.   
  25.     public static class PhoneContacts extends Activity {  
  26.         public static final Uri CONTENT_URI =  
  27.                 Uri.parse("content://contacts/live_folders/people_with_phones");  
  28.   
  29.         @Override  
  30.         protected void onCreate(Bundle savedInstanceState) {  
  31.             super.onCreate(savedInstanceState);  
  32.   
  33.             final Intent intent = getIntent();  
  34.             final String action = intent.getAction();  
  35.   
  36.             if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {  
  37.                 setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,  
  38.                         getString(R.string.liveFolder_phones_label),  
  39.                         R.drawable.ic_launcher_folder_live_contacts_phone));  
  40.             } else {  
  41.                 setResult(RESULT_CANCELED);  
  42.             }  
  43.   
  44.             finish();  
  45.         }  
  46.     }  
  47.   
  48.     public static class AllContacts extends Activity {  
  49.         public static final Uri CONTENT_URI =  
  50.                 Uri.parse("content://contacts/live_folders/people");  
  51.   
  52.         @Override  
  53.         protected void onCreate(Bundle savedInstanceState) {  
  54.             super.onCreate(savedInstanceState);  
  55.   
  56.             final Intent intent = getIntent();  
  57.             final String action = intent.getAction();  
  58.   
  59.             if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {  
  60.                 setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,  
  61.                         getString(R.string.liveFolder_all_label),  
  62.                         R.drawable.ic_launcher_folder_live_contacts));  
  63.             } else {  
  64.                 setResult(RESULT_CANCELED);  
  65.             }  
  66.   
  67.             finish();  
  68.         }  
  69.     }  
  70.   
  71.     private static Intent createLiveFolder(Context context, Uri uri, String name,  
  72.             int icon) {  
  73.   
  74.         final Intent intent = new Intent();  
  75.   
  76.         intent.setData(uri);  
  77.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT,  
  78.                 new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI));  
  79.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name);  
  80.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,  
  81.                 Intent.ShortcutIconResource.fromContext(context, icon));  
  82.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);  
  83.   
  84.         return intent;  
  85.     }  
  86. }  


//////////////////// 
// 

Java代码 复制代码 收藏代码
  1.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT,   
  2.                 new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI));   
  3. 这个在用的时候。 如果你用的uri读出来没有一个叫name的表项,   
  4. 那这个ACTION_VIEW会失败,所以需要有个叫name的,作为livefolder显示出来的东西。   
  5.   
  6. 比如系统的contactsprovider 里面  大概3790行   
  7.             case LIVE_FOLDERS_CONTACTS_GROUP_NAME:   
  8.                 qb.setTables(mDbHelper.getContactView());   
  9.                 qb.setProjectionMap(sLiveFoldersProjectionMap);   
  10.                 qb.appendWhere(CONTACTS_IN_GROUP_SELECT);   
  11.                 selectionArgs = insertSelectionArg(selectionArgs, uri.getLastPathSegment());   
  12.                 break;   
  13.   
  14. 这里qb.setProjectionMap(sLiveFoldersProjectionMap); 就是把有一个项作为name显示   
  15. //contactsProvider2.java line 854    
  16.        sLiveFoldersProjectionMap = new HashMap<String, String>();   
  17.         sLiveFoldersProjectionMap.put(LiveFolders._ID,   
  18.                 Contacts._ID + " AS " + LiveFolders._ID);   
  19.         sLiveFoldersProjectionMap.put(LiveFolders.NAME,   
  20.                 Contacts.DISPLAY_NAME + " AS " + LiveFolders.NAME);  
  1.         intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT,  
  2.                 new Intent(Intent.ACTION_VIEW, Contacts.CONTENT_URI));  
  3. 这个在用的时候。 如果你用的uri读出来没有一个叫name的表项,  
  4. 那这个ACTION_VIEW会失败,所以需要有个叫name的,作为livefolder显示出来的东西。  
  5.   
  6. 比如系统的contactsprovider 里面  大概3790行  
  7.             case LIVE_FOLDERS_CONTACTS_GROUP_NAME:  
  8.                 qb.setTables(mDbHelper.getContactView());  
  9.                 qb.setProjectionMap(sLiveFoldersProjectionMap);  
  10.                 qb.appendWhere(CONTACTS_IN_GROUP_SELECT);  
  11.                 selectionArgs = insertSelectionArg(selectionArgs, uri.getLastPathSegment());  
  12.                 break;  
  13.   
  14. 这里qb.setProjectionMap(sLiveFoldersProjectionMap); 就是把有一个项作为name显示  
  15. //contactsProvider2.java line 854   
  16.        sLiveFoldersProjectionMap = new HashMap<String, String>();  
  17.         sLiveFoldersProjectionMap.put(LiveFolders._ID,  
  18.                 Contacts._ID + " AS " + LiveFolders._ID);  
  19.         sLiveFoldersProjectionMap.put(LiveFolders.NAME,  
  20.                 Contacts.DISPLAY_NAME + " AS " + LiveFolders.NAME);  



自己实现一contentprovider来做这个事情的时候也需要实现一个 name作为显示, 
即在cursor query的时候加入比如select xxx as name, 在projection里加。 
说不清了。。。 
//一般还是不要自己造contentprovider了。。 系统的差不多够用 
//问题是怎么在系统里找到所有的uri? 嘿嘿。我不会- - 

这里转个大大的博克 
http://kuikui.iteye.com/blog/318627 
刚起步的时候经常困扰我们的是一些本来容易解决的问题,往往我们会花掉很大的力气去找解决的办法,最后才知道原来这么简单,这就是英文世界造成的。 

Intent在 Android应用开发中,占有很大的分量,关于Intent在Android中的作用在网络上已经有很多资料了,这里不再累赘,本人喜欢直来直去。在网上看到很多关于Intent的资料,说那么多,你也许还是一头雾水,到底如何使用Intent呢?这里总结一些重用的Intent使用,仅供参考。 

下面直接给我学习的实例片段。 



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,调拨打电话界面 

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,掉用发邮件 

Uri emailUri = Uri.parse("mailto:shenrenkui@gmail.com"); 

returnIt = new Intent(Intent.ACTION_SENDTO, emailUri); 

9,发邮件 

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,发短信 

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,直接发邮件 

Uri smsToUri = Uri.parse("smsto://100861"); 

returnIt = new Intent(Intent.ACTION_SENDTO, smsToUri); 

returnIt.putExtra("sms_body", "shenrenkui"); 

12,发彩信 

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直接调用startActivity(returnIt)就ok了

posted @ 2012-12-24 17:21  GreyWolf  阅读(350)  评论(0编辑  收藏  举报