桌面快捷键和桌面livefolder
// to create live folder on "home" screen
- 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);
- }
- 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.
- 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 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 .
- <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>
- <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>
///////////////////////////////////////////////////////////////////////////////
// 系统的contacts 在桌面livefolder添加快捷方式的代码如下。想要在livefolder中添加// 其他app的快捷方式,也可以依法炮制
- 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;
- }
- }
- 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);
- 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);
自己实现一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了