{"id":1520,"date":"2012-09-05T18:15:22","date_gmt":"2012-09-05T10:15:22","guid":{"rendered":"http:\/\/leybreeze.com\/blog\/?p=1520"},"modified":"2012-09-05T18:15:59","modified_gmt":"2012-09-05T10:15:59","slug":"android%e4%b8%ad%e6%8e%a5%e5%8f%97%e6%9d%a5%e8%87%aa%e5%85%b6%e4%bb%96%e5%ba%94%e7%94%a8%e7%9a%84%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"http:\/\/leybreeze.com\/blog\/?p=1520","title":{"rendered":"Android\u4e2d\u63a5\u53d7\u6765\u81ea\u5176\u4ed6\u5e94\u7528\u7684\u5185\u5bb9"},"content":{"rendered":"<p>Mainfest \u6587\u4ef6\u4ee3\u7801\uff1a<\/p>\n<p>&lt;activity android:name=&#8221;.IntentReceiver&#8221; &gt;<br \/>\n&lt;intent-filter&gt;<br \/>\n&lt;action android:name=&#8221;android.intent.action.SEND&#8221; \/&gt;<br \/>\n&lt;category android:name=&#8221;android.intent.category.DEFAULT&#8221; \/&gt;<br \/>\n&lt;data android:mimeType=&#8221;image\/*&#8221; \/&gt;<br \/>\n&lt;\/intent-filter&gt;<br \/>\n&lt;intent-filter&gt;<br \/>\n&lt;action android:name=&#8221;android.intent.action.SEND&#8221; \/&gt;<br \/>\n&lt;category android:name=&#8221;android.intent.category.DEFAULT&#8221; \/&gt;<br \/>\n&lt;data android:mimeType=&#8221;text\/plain&#8221; \/&gt;<br \/>\n&lt;\/intent-filter&gt;<br \/>\n&lt;intent-filter&gt;<br \/>\n&lt;action android:name=&#8221;android.intent.action.SEND_MULTIPLE&#8221; \/&gt;<br \/>\n&lt;category android:name=&#8221;android.intent.category.DEFAULT&#8221; \/&gt;<br \/>\n&lt;data android:mimeType=&#8221;image\/*&#8221; \/&gt;<br \/>\n&lt;\/intent-filter&gt;<br \/>\n&lt;\/activity&gt;<\/p>\n<p>\u8303\u4f8b\uff1a<\/p>\n<pre lang=\"JAVA\">void onCreate (Bundle savedInstanceState) {\r\n    ...\r\n    \/\/ \u83b7\u53d6 intent\u3001 action \u4ee5\u53ca MIME \u7c7b\u578b\uff0c\u8fd9\u4e9b\u662f\u4e00\u4e2a\u610f\u56fe\u7684\u4e3b\u8981\u5185\u5bb9\r\n    Intent intent = getIntent();\r\n    String action = intent.getAction();\r\n    String type = intent.getType();\r\n\r\n    if (Intent.ACTION_SEND.equals(action) &amp;&amp; type != null) {\r\n        if (\"text\/plain\".equals(type)) {\r\n            handleSendText(intent); \/\/ \u5904\u7406\u6536\u5230\u7684\u6587\u672c\r\n        } else if (type.startsWith(\"image\/\")) {\r\n            handleSendImage(intent); \/\/ \u5904\u7406\u6536\u5230\u7684\u56fe\u50cf\r\n        }\r\n    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) &amp;&amp; type != null) {\r\n        if (type.startsWith(\"image\/\")) {\r\n            handleSendMultipleImages(intent); \/\/ \u5904\u7406\u6536\u5230\u7684\u591a\u4e2a\u56fe\u50cf\r\n        }\r\n    } else {\r\n        \/\/ \u8fd8\u53ef\u4ee5\u6dfb\u52a0\u5176\u4ed6\u7c7b\u578b\u610f\u56fe\u7684\u5904\u7406\r\n    }\r\n    ...\r\n}\r\n\r\nvoid handleSendText(Intent intent) {\r\n    String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);\r\n    if (sharedText != null) {\r\n        \/\/ \u66f4\u65b0 UI \u6765\u53cd\u6620\u6536\u5230\u7684\u5185\u5bb9\r\n    }\r\n}\r\n\r\nvoid handleSendImage(Intent intent) {\r\n    Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);\r\n    if (imageUri != null) {\r\n        \/\/ \u66f4\u65b0 UI \u6765\u53cd\u6620\u6536\u5230\u7684\u5185\u5bb9\r\n    }\r\n}\r\n\r\nvoid handleSendMultipleImages(Intent intent) {\r\n    ArrayList imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);\r\n    if (imageUris != null) {\r\n        \/\/ \u66f4\u65b0 UI \u6765\u53cd\u6620\u6536\u5230\u7684\u5185\u5bb9\r\n    }\r\n}<\/pre>\n<p>\u8bf4\u660e\uff1a\u901a\u8fc7\u5728 Manifest \u6587\u4ef6\u4e2d\u58f0\u660e\u76f8\u5e94\u7684\u610f\u56fe\u8fc7\u6ee4\u5668\uff0c\u5c31\u53ef\u4ee5\u63a5\u6536\u6765\u81ea\u5176\u4ed6\u5e94\u7528\u7684\u6570\u636e\u4ee5\u4f9b\u5728\u81ea\u5df1\u7684\u5e94\u7528\u4e2d\u8fdb\u884c\u5904\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mainfest \u6587\u4ef6\u4ee3\u7801\uff1a &lt;activity android:name=&#8221;.Intent &hellip; <a href=\"http:\/\/leybreeze.com\/blog\/?p=1520\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cAndroid\u4e2d\u63a5\u53d7\u6765\u81ea\u5176\u4ed6\u5e94\u7528\u7684\u5185\u5bb9\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[101,40],"_links":{"self":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1520"}],"collection":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1520"}],"version-history":[{"count":2,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1520\/revisions"}],"predecessor-version":[{"id":1522,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1520\/revisions\/1522"}],"wp:attachment":[{"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1520"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/leybreeze.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}