{"id":3462,"date":"2023-08-22T15:08:42","date_gmt":"2023-08-22T07:08:42","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=3462"},"modified":"2023-08-22T15:08:42","modified_gmt":"2023-08-22T07:08:42","slug":"android-apk%e7%94%9f%e6%88%90%e4%ba%8c%e7%bb%b4%e7%a0%81%e9%9c%80%e8%a6%81%e6%b3%a8%e6%84%8f%e5%93%aa%e4%ba%9b%e7%bb%86%e8%8a%82%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/3462\/","title":{"rendered":"android apk\u751f\u6210\u4e8c\u7ef4\u7801\u9700\u8981\u6ce8\u610f\u54ea\u4e9b\u7ec6\u8282\uff1f"},"content":{"rendered":"

\u751f\u6210\u4e8c\u7ef4\u7801\u662f\u4e00\u79cd\u5c06\u6587\u672c\u4fe1\u606f\u7f16\u7801\u6210\u4e00\u7ec4\u9ed1\u767d\u65b9\u5757\u7684\u56fe\u50cf\u7684\u6280\u672f\u3002\u5728Android\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u6765\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u7136\u540e\u5c06\u5176\u5448\u73b0\u5728\u5e94\u7528\u754c\u9762\u4e0a\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u539f\u7406\u53ca\u8be6\u7ec6\u6b65\u9aa4\u3002<\/p>\n

\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u539f\u7406\uff1a<\/p>\n

1. \u521d\u59cb\u5316\u4e00\u4e2a\u4e8c\u7ef4\u7801\u5bf9\u8c61\u3002<\/p>\n

2. \u8bbe\u7f6e\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9\u548c\u5c3a\u5bf8\u3002<\/p>\n

3.<\/p>\n

<\/figure>\n<\/p>\n

\u901a\u8fc7\u4e8c\u7ef4\u7801\u5bf9\u8c61\u7684\u7f16\u7801\u65b9\u6cd5\uff0c\u5c06\u5185\u5bb9\u7f16\u7801\u6210\u4e8c\u7ef4\u7801\u56fe\u50cf\u3002<\/p>\n

4. \u5c06\u751f\u6210\u7684\u4e8c\u7ef4\u7801\u56fe\u50cf\u5448\u73b0\u5728\u5e94\u7528\u754c\u9762\u4e0a\u3002<\/p>\n

\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/p>\n

1. \u5bfc\u5165\u7b2c\u4e09\u65b9\u5e93<\/p>\n

\u5728\u9879\u76ee\u7684build.gradle\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4f9d\u8d56\uff1a<\/p>\n

“`<\/p>\n

implementation ‘com.google.zxing:core:3.4.0’<\/p>\n

“`<\/p>\n

2. \u521b\u5efa\u4e00\u4e2a\u65b9\u6cd5\u6765\u751f\u6210\u4e8c\u7ef4\u7801\u56fe\u50cf<\/p>\n

“`java<\/p>\n

private Bitmap generateQRCode(String content) {<\/p>\n

try {<\/p>\n

\/\/ \u521d\u59cb\u5316\u4e00\u4e2a\u4e8c\u7ef4\u7801\u5bf9\u8c61<\/p>\n

app\u6e90\u7801\u6253\u5305\u751f\u6210apk<\/a> QRCodeWriter writer = new QRCodeWriter();<\/p>\n

\/\/ \u8bbe\u7f6e\u4e8c\u7ef4\u7801\u7684\u5185\u5bb9\u548c\u5c3a\u5bf8<\/p>\n

BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512);<\/p>\n

\/\/ \u521b\u5efa\u4e00\u4e2a\u4f4d\u56fe\u5bf9\u8c61\u5e76\u8bbe\u7f6e\u50cf\u7d20<\/p>\n

int width = bitMatrix.getWidth();<\/p>\n

int height = bitMatrix.getHeight();<\/p>\n

Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);<\/p>\n

\/\/ \u904d\u5386\u6bcf\u4e2a\u50cf\u7d20\u70b9\uff0c\u8bbe\u7f6e\u4e3a\u9ed1\u8272\u6216\u767d\u8272<\/p>\n

for (int x = 0; x <\/p>\n

for (int y = 0; y <\/p>\n

bitmap.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);<\/p>\n

}<\/p>\n

}<\/p>\n

return bitmap;<\/p>\n

} catch (WriterException e) {<\/p>\n

e.printStackTrace();<\/p>\n

return null;<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

3. \u8c03\u7528\u65b9\u6cd5\u751f\u6210\u4e8c\u7ef4\u7801\u56fe\u50cf\u5e76\u663e\u793a\u5728\u5e94\u7528\u754c\u9762\u4e0a<\/p>\n

“`java<\/p>\n

private void generateAndShowQRCode(Strin\u5b89\u5353apk\u5f00\u53d1\u8f6f\u4ef6<\/a>g content) {<\/p>\n

ImageView imageView = findViewById(R.id.qr_code_image_view);<\/p>\n

Bitmap bitmap = generateQRCode(content);<\/p>\n

imageView.setImageBitmap(bitmap);<\/p>\n

}<\/p>\n

“`<\/p>\n

4. \u5728\u5e94\u7528\u754c\u9762\u4e0a\u6dfb\u52a0\u4e00\u4e2aImageView\u6765\u663e\u793a\u4e8c\u7ef4\u7801\u56fe\u50cf<\/p>\n

“`xml<\/p>\n<\/p>\n

android:id=”@+id\/qr_code_image_view”<\/p>\n

android:layout_width=”wrap_content”<\/p>\n

android:layout_height=”wrap_content”<\/p>\n

android:layout_centerInParent=”true”<\/p>\n

android:scaleType=”fitCenter”\/><\/p>\n

“`<\/p>\n

\u4ee5\u4e0a\u5c31\u662f\u751f\u6210Android APK\u4e8c\u7ef4\u7801\u7684\u539f\u7406\u53ca\u8be6\u7ec6\u6b65\u9aa4\u3002\u901a\u8fc7\u5bfc\u5165\u7b2c\u4e09\u65b9\u5e93\u3001\u521b\u5efa\u65b9\u6cd5\u751f\u6210\u4e8c\u7ef4\u7801\u56fe\u50cf\uff0c\u7136\u540e\u5c06\u5176\u663e\u793a\u5728\u5e94\u7528\u754c\u9762\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5b9e\u73b0\u4e8c\u7ef4\u7801\u7684\u751f\u6210\u529f\u80fd\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"

\u751f\u6210\u4e8c\u7ef4\u7801\u662f\u4e00\u79cd\u5c06\u6587\u672c\u4fe1\u606f\u7f16\u7801\u6210\u4e00\u7ec4\u9ed1\u767d\u65b9\u5757\u7684\u56fe\u50cf\u7684\u6280\u672f\u3002\u5728Android\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u6765\u751f\u6210\u4e8c\u7ef4\u7801\uff0c\u7136\u540e\u5c06\u5176\u5448\u73b0\u5728\u5e94\u7528\u754c\u9762\u4e0a\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u539f\u7406\u53ca\u8be6\u7ec6\u6b65\u9aa4\u3002\u751f\u6210\u4e8c\u7ef4\u7801\u7684\u539f\u7406\uff1a<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[6935,2598,6933,6934,185],"topic":[],"class_list":["post-3462","post","type-post","status-publish","format-standard","hentry","category-appkf","tag-androidapk","tag-2598","tag-apk","tag-6934","tag-185"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/3462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=3462"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/3462\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=3462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=3462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=3462"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=3462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}