{"id":292,"date":"2017-01-24T10:53:55","date_gmt":"2017-01-24T02:53:55","guid":{"rendered":"http:\/\/www.prayerlaputa.com\/?p=292"},"modified":"2017-01-24T10:53:55","modified_gmt":"2017-01-24T02:53:55","slug":"android%e8%8e%b7%e5%8f%96%e7%9b%b8%e5%86%8c%e5%9b%be%e7%89%87%e4%bb%a5%e5%8f%8a%e8%8e%b7%e5%8f%96%e6%8b%8d%e7%85%a7%e7%85%a7%e7%89%87","status":"publish","type":"post","link":"http:\/\/prayerlaputa.com\/?p=292","title":{"rendered":"android\u83b7\u53d6\u76f8\u518c\u56fe\u7247\u4ee5\u53ca\u83b7\u53d6\u62cd\u7167\u7167\u7247"},"content":{"rendered":"<p>\u4e4b\u524d\u5de5\u4f5c\u65f6\u9047\u5230\u7684\u95ee\u9898\uff0c\u8d81\u7740\u6625\u8282\u5de5\u4f5c\u538b\u529b\u4e0d\u5927\uff0c\u603b\u7ed3\u4e00\u4e0b\u3002<br \/>\n\u58f0\u660e\uff1a\u672c\u6587\u90e8\u5206\u4ee3\u7801\u53d6\u81ea<a href=\"http:\/\/blog.csdn.net\/beyond0525\/article\/details\/8939984\">Android\u5f00\u53d1\u4e4b\u83b7\u53d6\u76f8\u518c\u7167\u7247\u548c\u83b7\u53d6\u62cd\u7167\u7167\u7247<\/a>\u00a0\u5e76\u505a\u4e86\u4fee\u6539<br \/>\n1\u3001\u4ece\u76f8\u518c\u6216\u662f\u6587\u4ef6\u7ba1\u7406\u5668\u83b7\u53d6<br \/>\n\u5728android\u4e2d\u4ece\u672c\u5730\u83b7\u53d6\u56fe\u7247\uff08\u4e0d\u7ba1\u662f\u76f8\u518c\u6216\u662f\u6587\u4ef6\u7cfb\u7edf\uff09\uff0c\u8c03\u7528\u5982\u4e0bIntent\u5373\u53ef\uff1a<!--more--><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\tpublic static void getImageFromAlbum(Activity activty, int requestCode) {\n\t\tIntent intent = new Intent(Intent.ACTION_PICK);\n\t\tintent.setType(&quot;image\/*&quot;);\/\/ \u76f8\u7247\u7c7b\u578b\n\t\tactivty.startActivityForResult(intent, requestCode);\n\t}\n<\/pre>\n<p>\u8c03\u7528\u8be5Intent\u540e\uff0c\u5c06\u663e\u793a\u76f8\u518c\u3001\u6587\u4ef6\u7cfb\u7edf\u56fe\u6807\uff0c\u7528\u6237\u9009\u62e9\u540e\u5c06\u8fd4\u56de\uff0c\u6211\u4eec\u5728onActivityReSult\u4e2d\u53ef\u4ee5\u83b7\u53d6\u7528\u6237\u9009\u4e2d\u56fe\u7247\u7684Uri<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\tpublic void onActivityResult(int requestCode, int resultCode, Intent data){\n\t\tif(Activity.RESULT_OK == resultCode){\n\t\t\tif( ALBUM_IMAGE_REQ_CODE == requestCode){\n\t\t\t\t\/\/do something to the album image\n\t\t\t\tUri imageUri = data.getData();\n\t\t\t}\n\t\t}\n\t}\n<\/pre>\n<p>2\u3001\u8c03\u7528\u7cfb\u7edf\u62cd\u7167\u529f\u80fd\u83b7\u53d6\u7167\u7247<br \/>\n\u540c\u6837\u9700\u8981\u4ee5Intent\u7684\u65b9\u5f0f\u5b9e\u73b0\uff0c\u4e0b\u9762\u7684getImageFromCamera\u65b9\u6cd5\u5728\u8c03\u7528Intent\u65f6\u5982\u679c\u4e0d\u8bbe\u7f6eMediaStore.EXTRA_OUTPUT\uff0c\u90a3\u4e48\u5728onActivityResult\u4e2d\u901a\u8fc7Intent\u83b7\u53d6\u7684\u56fe\u7247\u53ea\u662f\u4e00\u4e2a\u7f29\u7565\u56fe\uff0c\u5e76\u4e0d\u662f\u6e05\u6670\u56fe\u7247\uff0c\u8981\u60f3\u62ff\u5230\u6e05\u6670\u7167\u7247\u5fc5\u987b\u5c06\u5176\u5148\u4fdd\u5b58\u5230SD\u5361\u4e0a\uff0c\u901a\u8fc7\u8bbe\u7f6eMediaStore.EXTRA_OUTPUT\u3001\u4f20\u5165\u4e00\u4e2aSD\u5361\u8def\u5f84\u7684Uri\u5bf9\u8c61\u5373\u53ef\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n        \/\/storageUri\u5fc5\u987b\u662f\u4e00\u4e2aSD\u5361\u5730\u5740\uff0c\u4ee5\u4fbf\u4fdd\u5b58\u6e05\u6670\u7167\u7247\n\tprotected void getImageFromCamera(Activity activity, int requestCode, Uri storageUri) {\n\t\tString state = Environment.getExternalStorageState();\n\t\tif (state.equals(Environment.MEDIA_MOUNTED)) {\n\t\t\tIntent getImageByCamera = new Intent(&quot;android.media.action.IMAGE_CAPTURE&quot;);\n\t\t\tgetImageByCamera.putExtra(MediaStore.EXTRA_OUTPUT, storageUri);\n\t\t\tactivity.startActivityForResult(getImageByCamera, requestCode);\n\t\t} else {\n\t\t\tToast.makeText(activity.getApplicationContext(), &quot;\u8bf7\u786e\u8ba4\u5df2\u7ecf\u63d2\u5165SD\u5361&quot;, Toast.LENGTH_LONG).show();\n\t\t}\n\t}\n        \/\/\u8f85\u52a9\u65b9\u6cd5\uff0c\u7528\u4e8e\u751f\u6210\u4e00\u4e2aSD\u5361\u8def\u5f84\u7684Uri\u5bf9\u8c61\n\tprivate static Uri getImageStorageUri(String sdSaveDir, String imageName){\n\t\tUri uri = null;\n\t\tString sdState = Environment.getExternalStorageState();\n\t\tif(sdState.equals(Environment.MEDIA_MOUNTED)){\n\t\t\tString imagePath = Environment.getExternalStorageDirectory().getPath()+&quot;\/&quot;+sdSaveDir;\n\t\t\tFile file = new File(imagePath);\n\t\t\tif(!file.exists()){\n\t\t\t\tfile.mkdir();\n\t\t\t}\n\t\t\timagePath = imagePath + &quot;\/&quot;+imageName;\n\t\t\turi = Uri.fromFile(new File(imagePath));\n\t\t} else {\n\t\t\t\/\/TODO throw exception or do something\n\t\t}\n\t\treturn uri;\n\t}\n<\/pre>\n<p>\u53c2\u8003\u8d44\u6599\uff1a<br \/>\n<a href=\"http:\/\/blog.csdn.net\/beyond0525\/article\/details\/8939984\">Android\u5f00\u53d1\u4e4b\u83b7\u53d6\u76f8\u518c\u7167\u7247\u548c\u83b7\u53d6\u62cd\u7167\u7167\u7247<\/a><br \/>\n<a href=\"http:\/\/blog.csdn.net\/beyond0525\/article\/details\/8940840\">Android\u5f00\u53d1\u4e4b\u83b7\u53d6\u76f8\u518c\u7167\u7247\u548c\u83b7\u53d6\u62cd\u7167\u7167\u7247\u4e8c<\/a><br \/>\n<a id=\"cb_post_title_url\" href=\"http:\/\/www.cnblogs.com\/tyrion\/p\/4436993.html\">Android\u4ece\u76f8\u518c\u83b7\u53d6\u56fe\u7247<\/a><br \/>\n<span class=\"link_title\"><a href=\"http:\/\/blog.csdn.net\/qq435757399\/article\/details\/8118528\">Android\u4ece\u76f8\u518c\u4e2d\u83b7\u53d6\u56fe\u7247\u4ee5\u53ca\u8def\u5f84<\/a><\/span><br \/>\n<a href=\"http:\/\/blog.csdn.net\/qq_26787115\/article\/details\/50583482\">Android Camera\u5f00\u53d1\u7cfb\u5217\uff08\u4e0a\uff09\u2014\u2014Camera\u7684\u57fa\u672c\u8c03\u7528\u4e0e\u5b9e\u73b0\u62cd\u7167\u529f\u80fd\u4ee5\u53ca\u83b7\u53d6\u62cd\u7167\u56fe\u7247\u52a0\u8f7d\u5927\u56fe\u7247<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u5de5\u4f5c\u65f6\u9047\u5230\u7684\u95ee\u9898\uff0c\u8d81\u7740\u6625\u8282\u5de5\u4f5c\u538b\u529b\u4e0d\u5927\uff0c\u603b\u7ed3\u4e00\u4e0b\u3002 \u58f0\u660e\uff1a\u672c\u6587\u90e8\u5206\u4ee3\u7801\u53d6\u81eaAndroid\u5f00\u53d1\u4e4b\u83b7\u53d6\u76f8\u518c\u7167\u7247 <a href='http:\/\/prayerlaputa.com\/?p=292' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[2,6],"tags":[26,33],"_links":{"self":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/292"}],"collection":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292"}],"version-history":[{"count":0,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions"}],"wp:attachment":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}