桌面快捷键和桌面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. }  
        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);
        }




// 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));  
        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代码 复制代码  收藏代码
  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>  
			<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的快捷方式,也可以依法炮制
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. }  
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代码 复制代码  收藏代码
  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);  
        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了
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值