{"id":58570,"date":"2024-10-12T20:52:43","date_gmt":"2024-10-12T12:52:43","guid":{"rendered":"https:\/\/server.hk\/cnblog\/58570\/"},"modified":"2024-10-12T20:52:43","modified_gmt":"2024-10-12T12:52:43","slug":"android%e6%87%89%e7%94%a8%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e5%85%b1%e4%ba%ab-android-%e5%85%a9%e5%80%8bapp%e5%85%b1%e4%ba%ab%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/58570\/","title":{"rendered":"Android\u61c9\u7528\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u5171\u4eab (android \u5169\u500bapp\u5171\u4eab\u6578\u64da\u5eab\u9023\u63a5)"},"content":{"rendered":"<h1 id=\"android%e6%87%89%e7%94%a8%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e5%85%b1%e4%ba%ab-oEpfbJtMFy\">Android\u61c9\u7528\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u5171\u4eab<\/h1>\n<p>\u5728\u73fe\u4eca\u7684\u79fb\u52d5\u61c9\u7528\u958b\u767c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u666e\u904d\u3002\u5c24\u5176\u662f\u5728Android\u5e73\u53f0\u4e0a\uff0c\u958b\u767c\u8005\u7d93\u5e38\u9700\u8981\u5728\u591a\u500b\u61c9\u7528\u4e4b\u9593\u5171\u4eab\u6578\u64da\u5eab\u9023\u63a5\u3002\u9019\u4e0d\u50c5\u80fd\u63d0\u9ad8\u6578\u64da\u7684\u53ef\u7528\u6027\uff0c\u9084\u80fd\u6e1b\u5c11\u8cc7\u6e90\u7684\u6d6a\u8cbb\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728Android\u61c9\u7528\u4e2d\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u5171\u4eab\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e5%85%b1%e4%ba%ab%e7%9a%84%e5%bf%85%e8%a6%81%e6%80%a7-oEpfbJtMFy\">\u6578\u64da\u5eab\u9023\u63a5\u5171\u4eab\u7684\u5fc5\u8981\u6027<\/h2>\n<p>\u5728\u8a31\u591a\u60c5\u6cc1\u4e0b\uff0c\u958b\u767c\u8005\u53ef\u80fd\u9700\u8981\u5728\u5169\u500b\u6216\u591a\u500bAndroid\u61c9\u7528\u4e4b\u9593\u5171\u4eab\u6578\u64da\u3002\u4f8b\u5982\uff0c\u4e00\u500b\u61c9\u7528\u53ef\u80fd\u8ca0\u8cac\u6578\u64da\u7684\u8f38\u5165\uff0c\u800c\u53e6\u4e00\u500b\u61c9\u7528\u5247\u8ca0\u8cac\u6578\u64da\u7684\u986f\u793a\u3002\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u82e5\u6bcf\u500b\u61c9\u7528\u90fd\u7368\u7acb\u5efa\u7acb\u6578\u64da\u5eab\u9023\u63a5\uff0c\u5c07\u6703\u5c0e\u81f4\u8cc7\u6e90\u7684\u6d6a\u8cbb\u548c\u6578\u64da\u7684\u4e00\u81f4\u6027\u554f\u984c\u3002\u56e0\u6b64\uff0c\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u7684\u5171\u4eab\u662f\u975e\u5e38\u5fc5\u8981\u7684\u3002<\/p>\n<h2 id=\"%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e5%85%b1%e4%ba%ab%e7%9a%84%e6%96%b9%e6%b3%95-oEpfbJtMFy\">\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u5171\u4eab\u7684\u65b9\u6cd5<\/h2>\n<p>\u5728Android\u4e2d\uff0c\u6709\u5e7e\u7a2e\u65b9\u6cd5\u53ef\u4ee5\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u7684\u5171\u4eab\u3002\u4ee5\u4e0b\u662f\u5e7e\u7a2e\u5e38\u898b\u7684\u65b9\u6cd5\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8contentprovider-oEpfbJtMFy\">1. \u4f7f\u7528ContentProvider<\/h3>\n<p>ContentProvider\u662fAndroid\u63d0\u4f9b\u7684\u4e00\u7a2e\u6a5f\u5236\uff0c\u5141\u8a31\u61c9\u7528\u4e4b\u9593\u5171\u4eab\u6578\u64da\u3002\u901a\u904eContentProvider\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5c07\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u66b4\u9732\u7d66\u5176\u4ed6\u61c9\u7528\uff0c\u4e26\u63d0\u4f9b\u4e00\u7d44API\u4f86\u9032\u884c\u6578\u64da\u7684\u589e\u522a\u6539\u67e5\u64cd\u4f5c\u3002<\/p>\n<pre><code>public class MyContentProvider extends ContentProvider {\n    @Override\n    public Uri insert(Uri uri, ContentValues values) {\n        \/\/ \u5be6\u73fe\u63d2\u5165\u6578\u64da\u7684\u908f\u8f2f\n    }\n\n    @Override\n    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {\n        \/\/ \u5be6\u73fe\u67e5\u8a62\u6578\u64da\u7684\u908f\u8f2f\n    }\n}\n<\/code><\/pre>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8broadcastreceiver-oEpfbJtMFy\">2. \u4f7f\u7528BroadcastReceiver<\/h3>\n<p>\u53e6\u4e00\u7a2e\u65b9\u6cd5\u662f\u4f7f\u7528BroadcastReceiver\u4f86\u5be6\u73fe\u61c9\u7528\u4e4b\u9593\u7684\u6578\u64da\u5171\u4eab\u3002\u7576\u4e00\u500b\u61c9\u7528\u9700\u8981\u66f4\u65b0\u6578\u64da\u6642\uff0c\u53ef\u4ee5\u767c\u9001\u4e00\u500b\u5ee3\u64ad\uff0c\u5176\u4ed6\u61c9\u7528\u53ef\u4ee5\u63a5\u6536\u5230\u9019\u500b\u5ee3\u64ad\u4e26\u9032\u884c\u76f8\u61c9\u7684\u6578\u64da\u66f4\u65b0\u3002<\/p>\n<pre><code>public class MyBroadcastReceiver extends BroadcastReceiver {\n    @Override\n    public void onReceive(Context context, Intent intent) {\n        \/\/ \u8655\u7406\u63a5\u6536\u5230\u7684\u5ee3\u64ad\n    }\n}\n<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8service-oEpfbJtMFy\">3. \u4f7f\u7528Service<\/h3>\n<p>\u958b\u767c\u8005\u9084\u53ef\u4ee5\u4f7f\u7528Service\u4f86\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u7684\u5171\u4eab\u3002\u901a\u904e\u5275\u5efa\u4e00\u500b\u7d81\u5b9a\u670d\u52d9\uff0c\u5176\u4ed6\u61c9\u7528\u53ef\u4ee5\u901a\u904e\u8a72\u670d\u52d9\u4f86\u8a2a\u554f\u6578\u64da\u5eab\u3002<\/p>\n<pre><code>public class MyService extends Service {\n    @Override\n    public IBinder onBind(Intent intent) {\n        return binder;\n    }\n}\n<\/code><\/pre>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-oEpfbJtMFy\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u5171\u4eab\u6642\uff0c\u958b\u767c\u8005\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u6578\u64da\u5b89\u5168\u6027\uff1a\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u6027\uff0c\u907f\u514d\u672a\u7d93\u6388\u6b0a\u7684\u8a2a\u554f\u3002<\/li>\n<li>\u6578\u64da\u4e00\u81f4\u6027\uff1a\u78ba\u4fdd\u5728\u591a\u500b\u61c9\u7528\u4e4b\u9593\u5171\u4eab\u6578\u64da\u6642\uff0c\u6578\u64da\u7684\u4e00\u81f4\u6027\u5f97\u5230\u7dad\u8b77\u3002<\/li>\n<li>\u6027\u80fd\u8003\u91cf\uff1a\u5728\u8a2d\u8a08\u6578\u64da\u5171\u4eab\u6a5f\u5236\u6642\uff0c\u8003\u616e\u5230\u6027\u80fd\u554f\u984c\uff0c\u907f\u514d\u9020\u6210\u4e0d\u5fc5\u8981\u7684\u5ef6\u9072\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-oEpfbJtMFy\">\u7d50\u8ad6<\/h2>\n<p>\u5728Android\u61c9\u7528\u958b\u767c\u4e2d\uff0c\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u5171\u4eab\u662f\u4e00\u500b\u91cd\u8981\u7684\u8ab2\u984c\u3002\u901a\u904e\u4f7f\u7528ContentProvider\u3001BroadcastReceiver\u548cService\u7b49\u6280\u8853\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u5728\u591a\u500b\u61c9\u7528\u4e4b\u9593\u5171\u4eab\u6578\u64da\u5eab\u9023\u63a5\u3002\u9019\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6578\u64da\u7684\u53ef\u7528\u6027\uff0c\u9084\u80fd\u6e1b\u5c11\u8cc7\u6e90\u7684\u6d6a\u8cbb\u3002\u5c0d\u65bc\u9700\u8981\u5728\u591a\u500b\u61c9\u7528\u4e4b\u9593\u9032\u884c\u6578\u64da\u4ea4\u4e92\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u638c\u63e1\u9019\u4e9b\u6280\u8853\u662f\u975e\u5e38\u5fc5\u8981\u7684\u3002<\/p>\n<p>\u5982\u9700\u9032\u4e00\u6b65\u4e86\u89e3\u5982\u4f55\u5728\u60a8\u7684\u61c9\u7528\u4e2d\u5be6\u73fe\u9ad8\u6548\u7684\u6578\u64da\u5eab\u9023\u63a5\u5171\u4eab\uff0c\u60a8\u53ef\u4ee5\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u652f\u6301\u60a8\u7684\u958b\u767c\u9700\u6c42\uff0c\u63d0\u4f9b\u7a69\u5b9a\u7684\u5f8c\u7aef\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u5728Android\u61c9\u7528\u4e2d\u5be6\u73fe\u6578\u64da\u5eab\u9023\u63a5\u5171\u4eab\uff0c\u8b93\u5169\u500b\u61c9\u7528\u8f15\u9b06\u5171\u4eab\u6578\u64da\uff0c\u63d0\u9ad8\u6548\u7387\u8207\u5354\u4f5c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-58570","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/58570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=58570"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/58570\/revisions"}],"predecessor-version":[{"id":58571,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/58570\/revisions\/58571"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=58570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=58570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=58570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}