{"id":724,"date":"2023-02-26T15:31:46","date_gmt":"2023-02-26T07:31:46","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=724"},"modified":"2023-04-29T17:13:27","modified_gmt":"2023-04-29T09:13:27","slug":"android-apply-and-release-power-lock","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/android-apply-and-release-power-lock\/","title":{"rendered":"Android\u7533\u8bf7\u7535\u6e90\u9501\u4e0e\u91ca\u653e\u7535\u6e90\u9501"},"content":{"rendered":"<p>\u6743\u9650\u914d\u7f6e<\/p>\n<pre><code class=\"language-xml\">&lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot;\/&gt;<\/code><\/pre>\n<p><!-- more --><\/p>\n<pre><code class=\"language-java\">\/\/ \u7533\u8bf7\u7535\u6e90\u9501\uff0c\u7981\u6b62\u4f11\u7720\nprivate WakeLock mWakeLock = null;\n\nprivate void acquireWakeLock() {\n    if (null == mWakeLock) {\n        PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);\n        mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this\n                .getClass().getCanonicalName());\n        if (null != mWakeLock) {\n            mWakeLock.acquire();\n        }\n    }\n}\n\n\/\/ \u91ca\u653e\u8bbe\u5907\u7535\u6e90\u9501\nprivate void releaseWakeLock() {\n    if (null != mWakeLock) {\n        mWakeLock.release();\n        mWakeLock = null;\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6743\u9650\u914d\u7f6e &lt;uses-permission android:name=&quot;android.per [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[213],"tags":[212],"class_list":["post-724","post","type-post","status-publish","format-standard","hentry","category-android-performance","tag-wakelock"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=724"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/724\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}