{"id":4705,"date":"2021-09-03T11:29:48","date_gmt":"2021-09-03T03:29:48","guid":{"rendered":"http:\/\/122.152.205.50\/wordpress\/?p=4705"},"modified":"2021-09-03T11:29:48","modified_gmt":"2021-09-03T03:29:48","slug":"%e7%9b%91%e5%90%ac%e5%ba%94%e7%94%a8%e6%98%af%e5%90%a6%e5%9b%9e%e5%88%b0%e6%a1%8c%e9%9d%a2","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=4705","title":{"rendered":"\u76d1\u542c\u5e94\u7528\u662f\u5426\u56de\u5230\u684c\u9762"},"content":{"rendered":"<p>\u7f51\u4e0a\u53ef\u80fd\u4f1a\u6709\u4e00\u79cd\u4e0d\u5168\u9762\u7684\u5b9e\u73b0\u65b9\u6cd5\uff1a\u901a\u8fc7\u76d1\u542c\u63a7\u4ef6\u7684\u751f\u547d\u5468\u671f\uff0c\u4f46\u662f\u4e00\u65e6app\u662f\u88ab\u5176\u5b83\u7684\u5e94\u7528\u906e\u6321\uff0c\u800c\u4e0d\u662f\u771f\u6b63\u56de\u5230\u684c\u9762\uff0c\u8fd9\u4e2a\u662f\u65e0\u6cd5\u5224\u65ad\u7684\u3002<\/p>\n<p>\u53c2\u7167\u8d44\u6599\uff1a<a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/blog.csdn.net\/wenzhi20102321\/article\/details\/78604136\">https:\/\/blog.csdn.net\/wenzhi20102321\/article\/details\/78604136<\/a><\/p>\n<p>\u5b9a\u4e49\u5e7f\u64ad\u7c7b<\/p>\n<pre><code class=\"language-java line-numbers\">public class HomeWatcherReceiver extends BroadcastReceiver {\n    private static final String LOG_TAG = \" TAG HomeReceiver\";\n\n    private static final String SYSTEM_DIALOG_REASON_KEY = \"reason\";\n    \/\/action\u5185\u7684\u67d0\u4e9breason\n    private static final String SYSTEM_DIALOG_REASON_RECENT_APPS = \"recentapps\";\/\/home\u952e\u65c1\u8fb9\u7684\u6700\u8fd1\u7a0b\u5e8f\u5217\u8868\u952e\n    private static final String SYSTEM_DIALOG_REASON_HOME_KEY = \"homekey\";\/\/\u6309\u4e0bhome\u952e\n    private static final String SYSTEM_DIALOG_REASON_LOCK = \"lock\";\/\/\u9501\u5c4f\u952e\n    private static final String SYSTEM_DIALOG_REASON_ASSIST = \"assist\";\/\/\u67d0\u4e9b\u4e09\u661f\u624b\u673a\u7684\u7a0b\u5e8f\u5217\u8868\u952e\n\n    @Override\n    public void onReceive(Context context, Intent intent) {\n        String action = intent.getAction();\n\/\/        App app = (App) context.getApplicationContext();\n        Logger.e(LOG_TAG, \"onReceive: action: \" + action);\n        if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {\/\/Action\n            \/\/ android.intent.action.CLOSE_SYSTEM_DIALOGS\n            String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);\n            Logger.e(LOG_TAG, \"reason: \" + reason);\n\n            if (SYSTEM_DIALOG_REASON_HOME_KEY.equals(reason)) { \/\/ \u77ed\u6309Home\u952e\n                \/\/\u53ef\u4ee5\u5728\u8fd9\u91cc\u5b9e\u73b0\u5173\u95ed\u7a0b\u5e8f\u64cd\u4f5c\u3002\u3002\u3002\n                Logger.e(LOG_TAG, \"homekey\");\n                List&lt;HomeWatchHelper.OnHomeKeyPressedListener&gt; homeKeyPressedListeners = HomeWatchHelper.getInstance().getHomeKeyPressedListeners();\n                boolean background = GlobalMagicJavaUtil.isBackground(context);\n                if(background == false){\n                    for (HomeWatchHelper.OnHomeKeyPressedListener item: homeKeyPressedListeners){\n                        item.onHomeKeyPressed();\n                    }\n                }else{\n                    Logger.e(LOG_TAG, \"\u5e94\u7528\u5df2\u7ecf\u5728\u540e\u53f0\u4e86\uff0chomekey\u5c31\u4e0d\u56de\u8c03\u4e86\u3002\");\n                }\n            } else if (SYSTEM_DIALOG_REASON_RECENT_APPS.equals(reason)) {\/\/Home\u952e\u65c1\u8fb9\u7684\u663e\u793a\u6700\u8fd1\u7684\u7a0b\u5e8f\u7684\u6309\u94ae\n                \/\/ \u957f\u6309Home\u952e \u6216\u8005 activity\u5207\u6362\u952e\n                Logger.e(LOG_TAG, \"long press home key or activity switch\");\n            } else if (SYSTEM_DIALOG_REASON_LOCK.equals(reason)) {  \/\/ \u9501\u5c4f\uff0c\u4f3c\u4e4e\u662f\u6ca1\u6709\u53cd\u5e94\uff0c\u76d1\u542cIntent.ACTION_SCREEN_OFF\u8fd9\u4e2aAction\u624d\u6709\u7528\n                Logger.e(LOG_TAG, \"lock\");\n            } else if (SYSTEM_DIALOG_REASON_ASSIST.equals(reason)) {   \/\/ samsung \u957f\u6309Home\u952e\n                Logger.e(LOG_TAG, \"assist\");\n            }\n\n        }\n    }\n\n}\n<\/code><\/pre>\n<p>\u6ce8\u518c\u4e0e\u89e3\u6ce8\u518c\u5e7f\u64ad<\/p>\n<pre><code class=\"language-java line-numbers\"> \/\/\u6ce8\u518c\u5e7f\u64ad\u63a5\u6536\u8005\uff0c\u76d1\u542cHome\u952e\n    private void registerHomeKeyReceiver(Context context) {\n        Logger.e(TAG, \"registerHomeKeyReceiver\");\n        mHomeKeyReceiver = new HomeWatcherReceiver();\n        IntentFilter homeFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);\n        context.registerReceiver(mHomeKeyReceiver, homeFilter);\n    }\n\n    \/\/\u53d6\u6d88\u76d1\u542c\u5e7f\u64ad\u63a5\u6536\u8005\n    private void unregisterHomeKeyReceiver(Context context) {\n        Logger.e(TAG, \"unregisterHomeKeyReceiver\");\n        if (null != mHomeKeyReceiver) {\n            context.unregisterReceiver(mHomeKeyReceiver);\n        }\n    }\n<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"4705\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>\u7f51\u4e0a\u53ef\u80fd\u4f1a\u6709\u4e00\u79cd\u4e0d\u5168\u9762\u7684\u5b9e\u73b0\u65b9\u6cd5\uff1a\u901a\u8fc7\u76d1\u542c\u63a7\u4ef6\u7684\u751f\u547d\u5468\u671f\uff0c\u4f46\u662f\u4e00\u65e6app\u662f\u88ab\u5176\u5b83\u7684\u5e94\u7528\u906e\u6321\uff0c\u800c\u4e0d\u662f\u771f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[229],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4705"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4705"}],"version-history":[{"count":1,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4705\/revisions"}],"predecessor-version":[{"id":4706,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/4705\/revisions\/4706"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4705"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}