{"id":126,"date":"2022-09-28T19:27:19","date_gmt":"2022-09-28T11:27:19","guid":{"rendered":"http:\/\/blog.nhl520.cn\/?p=126"},"modified":"2022-09-29T16:14:49","modified_gmt":"2022-09-29T08:14:49","slug":"android%e9%80%89%e6%8b%a9%e7%9b%b8%e5%86%8c%e9%87%8c%e7%9a%84%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/blog.nhl520.cn\/index.php\/2022\/09\/28\/android%e9%80%89%e6%8b%a9%e7%9b%b8%e5%86%8c%e9%87%8c%e7%9a%84%e5%9b%be%e7%89%87\/","title":{"rendered":"Android\u9009\u62e9\u76f8\u518c\u91cc\u7684\u56fe\u7247"},"content":{"rendered":"\n<p>\u4f5c\u8005\uff1a\u4e8c\u54c8<\/p>\n\n\n\n<p>\u4f5c\u8005qq\/wx\uff1a3132876589<\/p>\n\n\n\n<p>\u5b98\u65b9\u7f51\u7ad9\uff1a<a href=\"http:\/\/www.nhl520.cn\">www.nhl520.cn<\/a><\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p>\u6f14\u793a\u89c6\u9891\u5982\u4e0b<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"1280\" style=\"aspect-ratio: 800 \/ 1280;\" width=\"800\" controls src=\"https:\/\/blog.nhl520.cn\/wp-content\/uploads\/2022\/09\/QQ\u89c6\u989120220928210659.mp4\"><\/video><figcaption>\u539f\u521b\u89c6\u9891<\/figcaption><\/figure>\n<\/div><\/div>\n\n\n\n<p>1\u3001\u5148\u8bbe\u7f6eXML\u6587\u4ef6\u7684ID\u503c<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;ImageView\n android:id=\"@+id\/image_choose\"\n android:layout_width=\"250dp\"\n android:layout_height=\"250dp\"\n android:layout_centerHorizontal=\"true\"\n android:layout_marginTop=\"30dp\"\n android:padding=\"5dp\"\n android:src=\"@mipmap\/jh\" \/><\/pre>\n\n\n\n<p>2\u3001\u5728AndroidManifest.xml\u91cc\u9762\u6dfb\u52a0\u83b7\u53d6\u5b58\u50a8\u7684\u6743\u9650<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"> &lt;uses-permission android:name=\"android.permission.INTERNET\" \/><\/pre>\n\n\n\n<p>3\u3001\u5728Java\u754c\u9762\u8f93\u5165\u83b7\u53d6\u5355\u51fb\u7684ID\u503c\uff08\u5728onCreate\u91cc\u6dfb\u52a0\uff09<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">image_choose = findViewById(R.id.image_choose);<\/pre>\n\n\n\n<p>4\u3001\u7136\u540e\u8bbe\u7f6eImageView\u7684\u5355\u51fb\u9009\u62e9\u56fe\u7247\u7684\u4e8b\u4ef6\uff08\u5728onCreate\u91cc\u6dfb\u52a0\uff09<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">image_choose.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View view) {\n                switch (view.getId()) {\n                    case R.id.image_choose: {\n                        Intent intent = new Intent(Intent.ACTION_PICK, null);\n                        intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, \"image\/*\");\n                        startActivityForResult(intent, 0x1);\n                        break;\n\n                    }\n                }\n            }\n        });<\/pre>\n\n\n\n<p>5\u3001\u6700\u540e\u518d\u8bbe\u7f6eonActivityResult\u4e8b\u4ef6\uff08\u5728MainActivity\u91cc\u6dfb\u52a0\uff09<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">  protected void onActivityResult(int requestCode, int resultCode, Intent data) {\n            \/\/ TODO Auto-generated method stub\n\n            if (requestCode == 0x1 &amp;&amp; resultCode == RESULT_OK) {\n                if (data != null) {\n                    image_choose.setImageURI(data.getData());\n\n                    super.onActivityResult(requestCode, resultCode, data);\n                }\n            }\n    }<\/pre>\n\n\n\n<p>6\u3001\u5b8c\u6574\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package com.xiaolin.sjsq;\n\nimport androidx.appcompat.app.AppCompatActivity;\n\nimport android.content.Intent;\nimport android.os.Bundle;\nimport android.provider.MediaStore;\nimport android.view.View;\nimport android.widget.ImageView;\n\npublic class MainActivity extends AppCompatActivity {\n    private ImageView image_choose;\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n\n\n        image_choose = findViewById(R.id.image_choose);\n        image_choose.setOnClickListener(new View.OnClickListener() {\n            @Override\n            public void onClick(View view) {\n                switch (view.getId()) {\n                    case R.id.image_choose: {\n                        Intent intent = new Intent(Intent.ACTION_PICK, null);\n                        intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, \"image\/*\");\n                        startActivityForResult(intent, 0x1);\n                        break;\n\n                    }\n                }\n            }\n        });\n    }\n\n        protected void onActivityResult(int requestCode, int resultCode, Intent data) {\n            \/\/ TODO Auto-generated method stub\n\n            if (requestCode == 0x1 &amp;&amp; resultCode == RESULT_OK) {\n                if (data != null) {\n                    image_choose.setImageURI(data.getData());\n\n                    super.onActivityResult(requestCode, resultCode, data);\n                }\n            }\n    }\n\n\n\n\n        }\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\uff1a\u4e8c\u54c8 \u4f5c\u8005qq\/wx\uff1a3132876589 \u5b98\u65b9\u7f51\u7ad9\uff1awww.nhl520.cn \u6f14\u793a\u89c6\u9891\u5982\u4e0b 1\u3001\u5148\u8bbe\u7f6eXML\u6587\u4ef6\u7684ID\u503c 2\u3001\u5728AndroidManifest.xml\u91cc\u9762\u6dfb\u52a0\u83b7\u53d6\u5b58\u50a8\u7684\u6743\u9650 3\u3001\u5728Java\u754c\u9762\u8f93\u5165\u83b7\u53d6\u5355\u51fb\u7684ID\u503c\uff08\u5728onCreate\u91cc\u6dfb\u52a0\uff09 4\u3001\u7136\u540e\u8bbe\u7f6eImageView\u7684\u5355\u51fb\u9009\u62e9\u56fe\u7247\u7684\u4e8b\u4ef6\uff08\u5728onCreate\u91cc\u6dfb\u52a0\uff09 5\u3001\u6700\u540e\u518d\u8bbe\u7f6eonActivityResult\u4e8b\u4ef6\uff08 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":172,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android"],"_links":{"self":[{"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":13,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":141,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/posts\/126\/revisions\/141"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/media\/172"}],"wp:attachment":[{"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.nhl520.cn\/index.php\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}