{"id":1976,"date":"2022-11-25T18:00:46","date_gmt":"2022-11-25T10:00:46","guid":{"rendered":"https:\/\/app.applebyme.cn\/cloud\/appshangjia\/1976.html"},"modified":"2022-11-25T18:00:46","modified_gmt":"2022-11-25T10:00:46","slug":"%e5%b0%8f%e7%b1%b3miui-%e5%b0%8f%e9%83%a8%e4%bb%b6%e7%b3%bb%e7%bb%9f%e8%83%bd%e5%8a%9b%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/app.applebyme.cn\/cloud\/appshangjia\/1976.html","title":{"rendered":"\u5c0f\u7c73MIUI\u00a0\u5c0f\u90e8\u4ef6\u7cfb\u7edf\u80fd\u529b\u8bf4\u660e"},"content":{"rendered":"<p>\u5c0f\u7c73MIUI\u00a0\u5c0f\u90e8\u4ef6\u7cfb\u7edf\u80fd\u529b\u8bf4\u660e<\/p>\n<h2 id=\"_16\">1.\u8c03\u8d77&nbsp;MIUI&nbsp;<span class=\"wpcom_tag_link\">Widget<\/span>&nbsp;\u5546\u5e97\u91cc\u7684\u8be6\u60c5\u9875\uff0c\u6dfb\u52a0\u5e94\u7528\u7684&nbsp;MIUI&nbsp;Widget<\/h2>\n<h3 id=\"_16_0\">1.1.\u63cf\u8ff0<\/h3>\n<p>\u542f\u52a8 Widget \u8be6\u60c5\u9875\uff0c\u8be6\u60c5\u9875\u4f1a\u5305\u542b\u8be5 App \u901a\u8fc7\u5ba1\u6838\u7684Widget\u3002\u7528\u6237\u53ef\u4ee5\u5de6\u53f3\u6ed1\u52a8\u9884\u89c8\uff0c\u5e76\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u6dfb\u52a0\u5230\u684c\u9762\u3002<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124120830136.png\" alt=\"\u5c0f\u7c73MIUI\u00a0\u5c0f\u90e8\u4ef6\u7cfb\u7edf\u80fd\u529b\u8bf4\u660e\" \/><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124120830136.png\" alt=\"\u5c0f\u7c73MIUI\u00a0\u5c0f\u90e8\u4ef6\u7cfb\u7edf\u80fd\u529b\u8bf4\u660e\" \/><\/figure>\n<h5><\/h5>\n<h3 id=\"_16_1\">1.2.\u8c03\u7528\u65b9\u5f0f<\/h3>\n<pre class=\"wp-block-code\"><code>\u5173\u952e\u65b9\u6cd5\nappWidgetManager.requestPinAppWidget(myProvider, extras, <strong>null<\/strong>)\n\u4f7f\u7528 extras \u643a\u5e26\u53c2\u6570 \naddType: appWidgetDetail\nwidgetName: \u5c0f\u90e8\u4ef6name,\u53ef\u9009\u53c2\u6570\uff0c\u7528\u6765\u6307\u5b9a\u6253\u5f00\u8be6\u60c5\u9875\u540e\u5b9a\u4f4d\u5230\u7684\u7ec4\u4ef6\u3002\u5982\u679c\u4e0d\u586b\uff0c\u9ed8\u8ba4\u5b9a\u4f4d\u5230\u7b2c\u4e00\u4e2a\u3002\nwidgetExtraData: \u7528\u4e8e\u643a\u5e26\u81ea\u5b9a\u4e49\u53c2\u6570\uff0c\u643a\u5e26\u81ea\u5b9a\u4e49\u53c2\u6570\u7c7b\u578b\u53ea\u80fd\u662fString\uff0c\u6700\u591a\u643a\u5e265\u4e2a\uff0c\u8d85\u8fc75\u4e2a\u6240\u6709\u643a\u5e26\u7684\u81ea\u5b9a\u4e49\u53c2\u6570\u90fd\u5c06\u88ab\u629b\u5f03\u3002<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a\u8be5\u65b9\u6cd5\u4ec5\u652f\u6301 <span class=\"wpcom_tag_link\">Android 8.0<\/span> \u53ca\u4ee5\u4e0a\u7cfb\u7edf\u3002\u4e0d\u652f\u6301 MIUI Widget \u7684\u624b\u673a\u8c03\u7528<span class=\"wpcom_tag_link\">requestPinAppWidget<\/span> \u65b9\u6cd5\u4e0d\u4f1a\u8c03\u8d77 Widget \u5546\u5e97\u91cc\u7684\u8be6\u60c5\u9875\u3002<\/p>\n<h3 id=\"_16_2\">1.3.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code><strong>public<\/strong> <strong>void<\/strong> <strong>startAppWidgetPage<\/strong>(Context context){\n    AppWidgetManager appWidgetManager =  \n    AppWidgetManager.getInstance(context);\n    ComponentName myProvider = <strong>new<\/strong> ComponentName(<strong>this<\/strong>,  \n    ExampleWidgetProvider.class);\n    <strong>if<\/strong> (appWidgetManager.isRequestPinAppWidgetSupported()) {\n        Bundle extras = <strong>new<\/strong> Bundle();\n        extras.putString(\"addType\",\"appWidgetDetail\");\n        <em>\/\/ packageName \u4e3a\u5e94\u7528\u771f\u5b9e\u5305\u540d<\/em>\n\u2063        extras.putString(\"widgetName\",\n            \"packageName\/com.miui.ExampleWidgetProvider\");\n        Bundle dataBundle = <strong>new<\/strong> Bundle();\n        dataBundle.putString(\"dataKey1\",\"data1xxx\");\n        dataBundle.putString(\"dataKey2\",\"data2xxx\");\n        dataBundle.putString(\"dataKey3\",\"data3xxx\");\n        dataBundle.putString(\"dataKey4\",\"data4xxx\");\n        dataBundle.putString(\"dataKey5\",\"data5xxx\");\n        extras.putBundle(\"widgetExtraData\", dataBundle);\n        appWidgetManager.requestPinAppWidget(myProvider, extras, <strong>null<\/strong>);\n    }\n}\n\n<em>\/\/ \u83b7\u53d6\u81ea\u5b9a\u4e49\u53c2\u6570<\/em>\n<strong>public<\/strong> <strong>class<\/strong> <strong>ExampleWidgetProvider<\/strong> <strong>extends<\/strong> <strong>AppWidgetProvider<\/strong> {\n \n   @Override\n   <strong>public<\/strong> <strong>void<\/strong> <strong>onAppWidgetOptionsChanged<\/strong>(Context context, AppWidgetManager\n     appWidgetManager, <strong>int<\/strong> appWidgetId, Bundle newOptions) {\n         <strong>super<\/strong>.onAppWidgetOptionsChanged(context, appWidgetManager, \n         appWidgetId, newOptions);\n        <strong>if<\/strong>(extras != <strong>null<\/strong>){\n            Bundle dataBundle = extras.getBundle(\"widgetExtraData\");\n            dataBundle.getString(\"xxxkey\");\n        }   \n    }    \n}<\/code><\/pre>\n<h2 id=\"_17\">2.\u8bbe\u7f6e&nbsp;MIUI&nbsp;Widget\u5361\u7247\u72b6\u6001<\/h2>\n<h3 id=\"_17_0\">2.1.\u63cf\u8ff0<\/h3>\n<p>MIUI Widget \u4e5f\u53ef\u4ee5\u5728\u667a\u80fd\u52a9\u7406\uff08\u8d1f\u4e00\u5c4f\uff09\u8fdb\u884c\u5c55\u793a\u3002\u5e94\u7528\u53ef\u4ee5\u9009\u62e9\u5411\u7cfb\u7edf\u53d1\u9001\u5361\u7247\u7684\u4f18\u5148\u7ea7\u72b6\u6001\uff0cMIUI\u667a\u80fd\u52a9\u7406\uff08\u8d1f\u4e00\u5c4f\uff09\u4f1a\u6839\u636e\u5361\u7247\u72b6\u6001\u8fdb\u884c\u52a8\u6001\u7684\u6392\u5e8f\u3002<\/p>\n<h3 id=\"_17_1\">2.2.\u8c03\u7528\u65b9\u5f0f<\/h3>\n<pre class=\"wp-block-code\"><code>key:    miuiWidgetEventCode     \n\u7c7b\u578b:    String\n\u63cf\u8ff0\uff1a   \u4e8b\u4ef6code\u547d\u540d\u89c4\u5219\u8bf7\u53c2\u8003code\u4e8b\u4ef6\u8868\nkey:    miuiWidgetTimestamp\n\u7c7b\u578b\uff1a   String\n\u63cf\u8ff0\uff1a   \u72b6\u6001\u53d8\u5316\u65f6\u7684\u65f6\u95f4\u6233 \nappWidgetManager.updateAppWidgetOptions(widgetId, options);\nappWidgetManager.updateAppWidget(widgetId, views);<\/code><\/pre>\n<h3 id=\"_17_2\">2.3.code&nbsp;\u4e8b\u4ef6\u8868<\/h3>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>\u4e8b\u4ef6code\u547d\u540d\u89c4\u5219\u8bf7\u53c2\u8003\u4e0b\u8868\uff0c\u5177\u4f53\u4e8b\u4ef6\u4e0ecode\u5bf9\u5e94\u5173\u7cfb\u4ee5\u53cc\u65b9\u6c9f\u901a\u7ed3\u679c\u4e3a\u51c6<br \/>*\u65b0\u589e\u6216\u4fee\u6539\u4e8b\u4ef6\u9700\u4e0eMIUI\u5546\u52a1\u540c\u5b66\u8054\u7cfb\uff0c\u4e0a\u62a5\u672a\u786e\u8ba4\u7684\u4e8b\u4ef6code\u4e0d\u4f1a\u751f\u6548\uff0c\u6076\u610f\u9519\u62a5\u88ab\u7cfb\u7edf\u8bc6\u522b\u540e\u4f1a\u964d\u4f4e\u63a8\u8350\u6743\u91cd<\/td>\n<\/tr>\n<tr>\n<td>\u6838\u5fc3\u573a\u666f<\/td>\n<td>\u4e8b\u4ef6<\/td>\n<td>\u4e8b\u4ef6code<\/td>\n<td>\u5907\u6ce8<\/td>\n<\/tr>\n<tr>\n<td>\u91d1\u878d<br \/>\u80a1\u7968\u8bc1\u5238<\/td>\n<td>\u5c0f\u90e8\u4ef6\u5185\u6709\u80a1\u7968\/\u57fa\u91d1\u5728\u4ea4\u6613<\/td>\n<td>opening<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u5c0f\u90e8\u4ef6\u5185\u65e0\u80a1\u7968\/\u57fa\u91d1\u5728\u4ea4\u6613<\/td>\n<td>closing<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u51fa\u884c<\/td>\n<td>\u901a\u52e4\u65f6\u95f4<\/td>\n<td>commuting<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u975e\u901a\u52e4\u65f6\u95f4<\/td>\n<td>other<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u76f4\u64ad\/\u7535\u53f0<\/td>\n<td>\u5c0f\u90e8\u4ef6\u5185\u5c55\u793a\u5185\u5bb9\u201c\u76f4\u64ad\u4e2d\u201d<\/td>\n<td>live1<\/td>\n<td>\u4e0d\u540c\u7684\u4e8b\u4ef6\u53ef\u7528live1\u3001live2&#8230;\u533a\u5206<\/td>\n<\/tr>\n<tr>\n<td>\u5c0f\u90e8\u4ef6\u5185\u5c55\u793a\u5185\u5bb9\u201c\u91cd\u64ad\u4e2d\u201d<\/td>\n<td>replay<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u5c0f\u90e8\u4ef6\u5185\u5c55\u793a\u5185\u5bb9\u201c\u672a\u5f00\u64ad\u201d<\/td>\n<td>other<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u8fde\u63a5\u72b6\u6001<\/td>\n<td>\u5df2\u8fde\u63a5<\/td>\n<td>connected<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u672a\u8fde\u63a5<\/td>\n<td>disconnect<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>\u901a\u77e5\u63d0\u9192<\/td>\n<td>\u5c0f\u90e8\u4ef6\u5185\u5c55\u793a\u6709\u901a\u77e5\u63d0\u9192\u63d0\u9192<\/td>\n<td>notice1<\/td>\n<td>\u4e0d\u540c\u7684\u4e8b\u4ef6\u53ef\u7528notice1\u3001notice2&#8230;\u533a\u5206<\/td>\n<\/tr>\n<tr>\n<td>\u8fdb\u5ea6\u72b6\u6001<\/td>\n<td>\u5982\u201c\u6253\u8f66\u8fdb\u5ea6\u201d\u201c\u4e0b\u5355\u8fdb\u5ea6\u201d\u7b49<\/td>\n<td>progress1<\/td>\n<td>\u4e0d\u540c\u7684\u4e8b\u4ef6\u53ef\u7528progress1\u3001progress2&#8230;\u533a\u5206<\/td>\n<\/tr>\n<tr>\n<td>\u5185\u5bb9\u8d44\u8baf<\/td>\n<td>\u5982\u201c\u4eca\u65e5\u70ed\u95e8\u201d\u201c\u8bdd\u9898\u699c\u201d\u201c\u70ed\u641c\u699c\u201d\u7b49<\/td>\n<td>info1<\/td>\n<td>\u4e0d\u540c\u7684\u4e8b\u4ef6\u53ef\u7528info1\u3001info2&#8230;\u533a\u5206<\/td>\n<\/tr>\n<tr>\n<td>\u529f\u80fd\u8df3\u8f6c<\/td>\n<td>\u5c0f\u90e8\u4ef6\u4e3a\u7eaf\u5de5\u5177\u7c7b\u7684\u529f\u80fd\u8df3\u8f6c<\/td>\n<td>state1<\/td>\n<td>\u4e0d\u540c\u7684\u4e8b\u4ef6\u53ef\u7528state1\u3001state2&#8230;\u533a\u5206<\/td>\n<\/tr>\n<tr>\n<td>\u5176\u4ed6<\/td>\n<td>\u5c0f\u90e8\u4ef6\u7684\u515c\u5e95\u5c55\u793a\u65b9\u6848\u6216\u5176\u4ed6\u72b6\u6001<\/td>\n<td>other<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3 id=\"_17_3\">2.4.\u793a\u4f8b<\/h3>\n<ul>\n<li>\u666e\u901a Widget \uff1a\u5728 AppWidgetProvider \u7684 onUpdate \u65b9\u6cd5\uff0c\u8c03\u7528 updateAppWidgetOptions \u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<pre class=\"wp-block-code\"><code><strong>public<\/strong> <strong>class<\/strong> <strong>ExampleWidgetProvider<\/strong> <strong>extends<\/strong> <strong>AppWidgetProvider<\/strong> {\n    @Override\n    <strong>public<\/strong> <strong>void<\/strong> <strong>onUpdate<\/strong>(Context context, AppWidgetManager appWidgetManager, <strong>int<\/strong>&#091;] appWidgetIds) {\n        <em>\/\/ todo \u51c6\u5907\u5f85\u66f4\u65b0\u6570\u636e<\/em>\n        ....\n        <em>\/\/ \u66f4\u65b0\u6570\u636e<\/em>\n        <strong>for<\/strong> (<strong>int<\/strong> appWidgetId : appWidgetIds) {\n            RemoteViews views = <strong>new<\/strong> RemoteViews(context.getPackageName(), \n            R.layout.widget_ui);\n            Bundle options = <strong>new<\/strong> Bundle();\n            options.putString(\"miuiWidgetEventCode\", \"notice1\");\n            <strong>long<\/strong> currentTimeMillis = System.currentTimeMillis();\n            options.putString(\"miuiWidgetTimestamp\",\n            String.valueOf(currentTimeMillis));\n            appWidgetManager.updateAppWidgetOptions(widgetId, options);\n            appWidgetManager.updateAppWidget(widgetId, views);\n        }\n    }\n}<\/code><\/pre>\n<ul>\n<li>\u5217\u8868 Widget : notifyAppWidgetViewDataChanged \u66f4\u65b0\u540e\u8c03\u7528 updateAppWidget \u548cupdateAppWidgetOptions \u65b9\u6cd5<\/li>\n<\/ul>\n<pre class=\"wp-block-code\"><code><strong>public<\/strong> <strong>class<\/strong> <strong>ExampleWidgetProvider<\/strong> <strong>extends<\/strong> <strong>AppWidgetProvider<\/strong> {\n    @Override\n    <strong>public<\/strong> <strong>void<\/strong> <strong>onUpdate<\/strong>(Context context, AppWidgetManager appWidgetManager, <strong>int<\/strong>&#091;] appWidgetIds) {\n        <strong>for<\/strong> (<strong>int<\/strong> appWidgetId : appWidgetIds) {\n            <em>\/\/ todo \u51c6\u5907\u5f85\u66f4\u65b0\u6570\u636e<\/em>\n            ...\n            appWidgetManager.notifyAppWidgetViewDataChanged (mAppWidgetId,R.id.content);\n            <em>\/\/ \u66f4\u65b0\u6570\u636e\u540e\u8fdb\u884c\u72b6\u6001\u66f4\u65b0<\/em>\n            Bundle options = <strong>new<\/strong> Bundle();\n            options.putString(\"miuiWidgetEventCode\", \"notice1\");\n            <strong>long<\/strong> currentTimeMillis = System.currentTimeMillis();\n            options.putString(\"miuiWidgetTimestamp\",\n            String.valueOf(currentTimeMillis));\n            appWidgetManager.updateAppWidgetOptions(mAppWidgetId, options);\n            RemoteViews remoteViews = <strong>new<\/strong> RemoteViews(mContext.getPackageName(),             R.layout.widget_list_example);\n            appWidgetManager.updateAppWidget(mAppWidgetId, remoteViews);\n        }\n    }\n}<\/code><\/pre>\n<p>\u6ce8\u610f\uff1aupdateAppWidgetOptions \u9700\u8981\u5728 updateAppWidget ()\u65b9\u6cd5\u524d\uff0c\u5e76\u4e14\u4e24\u8005\u9700\u8981\u540c\u4e00\u7ebf\u7a0b\u3002<\/p>\n<h2 id=\"_18\">3.\u8bbe\u7f6e\u7f16\u8f91\u9875<\/h2>\n<h3 id=\"_18_0\">3.1.\u63cf\u8ff0<\/h3>\n<p>MIUI Widget \u989d\u5916\u63d0\u4f9b\u8fdb\u5165\u7f16\u8f91\u9875\u7684\u5165\u53e3\u3002\u7528\u6237\u70b9\u51fb\u7f16\u8f91\u6309\u94ae\uff0c\u53ef\u4ee5\u8fdb\u5165\u7f16\u8f91\u9875\u8fdb\u884c\u76f8\u5e94\u7684\u8bbe\u7f6e\u3002<\/p>\n<h3 id=\"_18_1\">3.2.\u8c03\u7528\u65b9\u6cd5\u4e0e\u53c2\u6570<\/h3>\n<pre class=\"wp-block-code\"><code>Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);\nString uriPath = \"widgetdemo:\/\/com.miui.widgetdemo\/widget\/WidgetEditActivity\";\noptions.putString(\"miuiEditUri\", uriPath);\nappWidgetManager.updateAppWidgetOptions(appWidgetId, options);\nappWidgetManager.updateAppWidget(widgetId, views);<\/code><\/pre>\n<h3 id=\"_18_2\">3.3.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code><strong>public<\/strong> <strong>class<\/strong> <strong>ExampleWidgetProvider<\/strong> <strong>extends<\/strong> <strong>AppWidgetProvider<\/strong> {\n    @Override\n    <strong>public<\/strong> <strong>void<\/strong> <strong>onUpdate<\/strong>(Context context, AppWidgetManager \n        appWidgetManager, <strong>int<\/strong>&#091;] appWidgetIds) {\n        <strong>for<\/strong> (<strong>int<\/strong> appWidgetId : appWidgetIds) {          \n            Bundle options =   \n            appWidgetManager.getAppWidgetOptions(appWidgetId);\n            String uriPath =            \"widgetdemo:\/\/com.miui.widgetdemo\/widget\/WidgetEditActivity\";\n            options.putString(\"miuiEditUri\", uriPath);\n            appWidgetManager.updateAppWidgetOptions(appWidgetId, options);\n            RemoteViews views =   \n            <strong>new<\/strong> RemoteViews(context.getPackageName(), \n            R.layout.widget_ui);\n            appWidgetManager.updateAppWidget(widgetId, views);\n        }\n        ....\n    }\n}\n<em>\/\/ \u901a\u8fc7 intent \u53ef\u4ee5\u83b7\u53d6\u70b9\u51fb\u7684appWidgetId<\/em>\n<strong>public<\/strong> <strong>class<\/strong> <strong>WidgetEditActivity<\/strong> <strong>extends<\/strong> <strong>AppCompatActivity<\/strong> {\n    @Override\n    <strong>protected<\/strong> <strong>void<\/strong> <strong>onCreate<\/strong>(Bundle savedInstanceState) {\n        Intent intent = getIntent();\n        <strong>int<\/strong> appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);\n    }\n}<\/code><\/pre>\n<h2 id=\"_19\">4.\u540c\u529f\u80fd MIUI Widget \u805a\u5408<\/h2>\n<h3 id=\"_19_0\">4.1.\u63cf\u8ff0<\/h3>\n<p>MIUI Widget \u53ef\u4ee5\u628a\u4e0d\u540c\u5c3a\u5bf8\u76f8\u540c\u529f\u80fd\u7684Widget \u5728\u8be6\u60c5\u9875\u4e2d\u805a\u5408\u5728\u4e00\u5757\u663e\u793a\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u6dfb\u52a0\u76f8\u5e94\u5c3a\u5bf8\u7684Widget\u3002<\/p>\n<h3 id=\"_19_1\">4.2.\u8c03\u7528\u65b9\u5f0f<\/h3>\n<p>\u5728AndroidManifest.xml \u6587\u4ef6\u4e2d AppWidgetProvider \u5bf9\u5e94\u7684receiver \u5982\u679clabel \u7684\u540d\u79f0\u76f8\u540c\u7684\u8bdd\u5c06\u4f1a\u88ab\u8ba4\u4e3a\u662f\u540c\u4e00\u529f\u80fd\u7684\u4e0d\u540c\u5c3a\u5bf8\u3002<\/p>\n<h3 id=\"_19_2\">4.3.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code>&lt;receiver\n    android:name=\"com.miui.widgetdemo.provider.ExampleWidgetProvider1\"\n    android:label=\"@string\/app_widget_group\"&gt;\n    ...\n&lt;\/receiver&gt;\n\n&lt;receiver\n    android:name=\"com.miui.widgetdemo.provider.ExampleWidgetProvider2\"\n    android:label=\"@string\/app_widget_group\"&gt;\n   ...\n&lt;\/receiver&gt;<\/code><\/pre>\n<h2 id=\"_20\">5.\u70b9\u51fb&nbsp;&nbsp;MIUI&nbsp;Widget&nbsp;\u8df3\u8f6c\u5e94\u7528\u9875\u9762<\/h2>\n<h3 id=\"_20_0\">5.1.\u63cf\u8ff0<\/h3>\n<p>\u5728 AppWidgetProvider \u7684onUpdate\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528 RemoteViews \u7684 setOnClickPendingIntent \u8bbe\u7f6e\u542f\u52a8\u7684 Intent \u3002\u4f7f\u7528 AppWidgetManager \u7684 updateAppWidget\u65b9\u6cd5\u5173\u8054RemoteViews \u548cWidget\u3002<\/p>\n<h3 id=\"_20_1\">5.2.\u53c2\u6570<\/h3>\n<pre class=\"wp-block-code\"><code><em>\/\/ viewId Widget \u5e03\u5c40 id<\/em>\n<em>\/\/ PendingIntent Intent\u7684\u5c01\u88c5<\/em>\n<em>\/\/ appWidgetId Widget \u7684 id\uff0c\u53ef\u5728 onUpdate \u65b9\u6cd5\u53c2\u6570\u4e2d\u83b7\u53d6<\/em>\n<em>\/\/ appWidgetManager widget \u7684\u7ba1\u7406\u5bf9\u8c61\uff0c\u53ef\u5728 onUpdate \u65b9\u6cd5\u53c2\u6570\u83b7\u53d6<\/em>\nremoteViews.setOnClickPendingIntent(<strong>int<\/strong> viewId, PendingIntent pendingIntent)\nappWidgetManager.updateAppWidget(<strong>int<\/strong> appWidgetId, RemoteViews views)\n<\/code><\/pre>\n<h3 id=\"_20_2\">5.3.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code><em>\/\/ step1: \u6784\u5efa\u8df3\u8f6c\u9875\u9762\u7684 PendingIntent<\/em>\nIntent intent = <strong>new<\/strong> Intent(context, ExampleActivity.class);\nPendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);\n<em>\/\/ step2: \u751f\u6210 RemoteViews \u5173\u8054 PendingIntent<\/em>\nRemoteViews views = <strong>new<\/strong> RemoteViews(context.getPackageName(), R.layout.appwidget_provider_layout);\nviews.setOnClickPendingIntent(R.id.button, pendingIntent);\n<em>\/\/ step3: \u5173\u8054 widget \u548c RemoteViews<\/em>\nappWidgetManager.updateAppWidget(appWidgetId, views);<\/code><\/pre>\n<h2 id=\"_21\">6.\u5224\u65ad&nbsp;MIUI&nbsp;Widget&nbsp;\u662f\u5426\u5df2\u7ecf\u6dfb\u52a0<\/h2>\n<h3 id=\"_21_0\">6.1.\u63cf\u8ff0<\/h3>\n<p>\u4f7f\u7528\u7cfb\u7edf AppWidgetManager \u7684 getAppWidgetIds\u65b9\u6cd5\u5224\u65ad\u67d0\u4e2aWidget\u662f\u5426\u5df2\u6dfb\u52a0\u3002<\/p>\n<h3 id=\"_21_1\">6.2.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code>ComponentName componentName = <strong>new<\/strong> ComponentName(getPackageName(), \"com.miui.ExampleAppWidgetProvider\");\n<strong>int<\/strong>&#091;] appWidgetIds = AppWidgetManager.getInstance(getApplicationContext()).getAppWidgetIds(componentName);\n<strong>if<\/strong>(appWidgetIds.length &gt; 0){\n    <em>\/\/ \u5df2\u6dfb\u52a0<\/em>\n} <strong>else<\/strong> {\n    <em>\/\/ \u672a\u6dfb\u52a0<\/em>\n}<\/code><\/pre>\n<h2 id=\"_22\">7.\u5224\u65ad\u662f\u5426\u652f\u6301MIUI&nbsp;Widget<\/h2>\n<h3 id=\"_22_0\">7.1.\u63cf\u8ff0<\/h3>\n<p>\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u793a\u4f8b\u65b9\u5f0f\u5224\u65ad\u5f53\u524d\u624b\u673a\u662f\u5426\u652f\u6301MIUI Widget\u3002<\/p>\n<h3 id=\"_22_1\">7.2.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code>@WorkerThread\n<strong>public<\/strong> <strong>boolean<\/strong> <strong>isMiuiWidgetSupported<\/strong>() {\n    Uri uri = \n    Uri.parse(\"content:\/\/com.miui.personalassistant.widget.external\");\n    <strong>boolean<\/strong> isMiuiWidgetSupported = <strong>false<\/strong>;\n    <strong>try<\/strong> {\n        Bundle bundle = getContentResolver().call(uri, \n        \"isMiuiWidgetSupported\", <strong>null<\/strong>, <strong>null<\/strong>);\n        <strong>if<\/strong> (bundle != <strong>null<\/strong>) {\n            isMiuiWidgetSupported = bundle.getBoolean(\"isMiuiWidgetSupported\");\n        }\n    } <strong>catch<\/strong> (Exception e) {\n        e.printStackTrace();\n    }\n    <strong>return<\/strong> isMiuiWidgetSupported;\n}<\/code><\/pre>\n<h2 id=\"_23\">8.\u5224\u65ad\u662f\u5426\u652f\u6301MIUI&nbsp;Widget&nbsp;\u5c0f\u90e8\u4ef6\u8be6\u60c5\u9875<\/h2>\n<h3 id=\"_23_0\">8.1.\u63cf\u8ff0<\/h3>\n<p>\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u793a\u4f8b\u65b9\u5f0f\u5224\u65ad\u5f53\u524d\u624b\u673a\u662f\u5426\u652f\u6301MIUI Widget \u8be6\u60c5\u9875\u3002\u4e3a\u4e86\u63d0\u5347\u7528\u6237\u4f53\u9a8c\uff0c\u90e8\u5206\u673a\u578b\u652f\u6301 MIUI Widget\uff08\u5305\u542bMIUI Widget \u7279\u6027\uff0c\u4f8b\u5982\u66dd\u5149\u5237\u65b0\u7b49\uff09, \u4f46\u4e0d\u652f\u6301\u8c03\u8d77MIUI Widget \u8be6\u60c5\u9875\u3002\u8fd9\u90e8\u5206\u673a\u578b\u6dfb\u52a0\u5c0f\u90e8\u4ef6\u7684\u65b9\u5f0f\u4e0e\u65e7\u7248\u7cfb\u7edf\u4e00\u81f4\u3002<\/p>\n<h3 id=\"_23_1\">8.2.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code>@WorkerThread\n<strong>public<\/strong> <strong>boolean<\/strong> <strong>isMiuiWidgetDetailPageSupported<\/strong>() {\n    Uri uri = \n    Uri.parse(\"content:\/\/com.miui.personalassistant.widget.external\");\n    <strong>boolean<\/strong> isMiuiWidgetDetailPageSupported = <strong>false<\/strong>;\n    <strong>try<\/strong> {\n        Bundle bundle = getContentResolver().call(uri, \n        \"isMiuiWidgetDetailPageSupported\", <strong>null<\/strong>, <strong>null<\/strong>);\n        <strong>if<\/strong> (bundle != <strong>null<\/strong>) {\n            isMiuiWidgetDetailPageSupported = bundle.getBoolean(\"isMiuiWidgetDetailPageSupported\");\n        }\n    } <strong>catch<\/strong> (Exception e) {\n        e.printStackTrace();\n    }\n    <strong>return<\/strong> isMiuiWidgetDetailPageSupported;\n}<\/code><\/pre>\n<h2 id=\"_24\">9.MIUI&nbsp;Widget&nbsp;\u4e0e&nbsp;Activity&nbsp;\u5207\u6362\u52a8\u753b<\/h2>\n<h3 id=\"_24_0\">9.1.\u63cf\u8ff0<\/h3>\n<p>MIUI \u7cfb\u7edf\u4e3aMIUI Widget \u548c Activity \u5207\u6362\u65f6\u589e\u52a0\u4e86\u8fc7\u6e21\u52a8\u753b\u3002\u5f00\u53d1\u8005\u53ef\u6839\u636e\u81ea\u8eab\u4e1a\u52a1\u573a\u666f\u51b3\u5b9a\u662f\u5426\u4f7f\u7528\u8fc7\u6e21\u52a8\u753b\u3002\u52a8\u753b\u9ed8\u8ba4\u5f00\u542f\uff0c\u5982\u679c\u4e0d\u4f7f\u7528\uff0c\u8bbe\u7f6e&#8221;miuiWidgetTransitionAnimation&#8221;\u4e3afalse\u3002<\/p>\n<h3 id=\"_24_1\">9.2.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code>&lt;receiver android:name=\"com.miui.ExampleWidgetProvider\" &gt;\n    &lt;meta-data\n    android:name=\"miuiWidget\"\n    android:value=\"true\" \/&gt;\n    <em>\/\/ \u5173\u95ed\u52a8\u753b<\/em>\n    &lt;meta-data\n    android:name=\"miuiWidgetTransitionAnimation\"\n    android:value=\"false\" \/&gt;\n\n    ...\n&lt;\/receiver&gt;<\/code><\/pre>\n<h2 id=\"_25\">10.App\u4e3b\u52a8\u5237\u65b0\u5c0f\u90e8\u4ef6<\/h2>\n<h3 id=\"_25_0\">10.1.\u63cf\u8ff0<\/h3>\n<p>\u5f53\u5e94\u7528\u5728\u524d\u53f0\u4f7f\u7528\u6216\u5728\u540e\u53f0\u5b58\u6d3b\u65f6\uff0c\u53ef\u8c03\u7528AppWidgetManager. updateAppWidget()\u65b9\u6cd5\uff0c\u4e3b\u52a8\u5237\u65b0\u5c0f\u90e8\u4ef6\u3002\u8fd9\u6837\u53ef\u4ee5\u63d0\u9ad8\u5c0f\u90e8\u4ef6\u5185\u5bb9\u7684\u5b9e\u65f6\u6027\u548c\u51c6\u786e\u6027\u3002<\/p>\n<h3 id=\"_25_1\">10.2.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code><em>\/\/ \u901a\u8fc7\u7ec4\u4ef6\u540d\u66f4\u65b0<\/em>\n<strong>public<\/strong> <strong>void<\/strong> <strong>updateWidget<\/strong>(Context context) {\n    <em>\/\/ R.layout.demo_appwidget_normal_example \u4e3a\u5c0f\u90e8\u4ef6\u5e03\u5c40\u6587\u4ef6\uff0c\u8fd9\u91cc\u4ec5\u793a\u4f8b<\/em>\n    RemoteViews remoteViews = <strong>new<\/strong> RemoteViews(context.getPackageName(),\n            R.layout.demo_appwidget_normal_example);\n    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);\n    <em>\/\/ NormalExampleWidgetProvider \u4e3a\u5c0f\u90e8\u4ef6\u7ec4\u4ef6\u540d\u5b57\uff0c\u8fd9\u91cc\u4ec5\u793a\u4f8b<\/em>\n    ComponentName componentName = <strong>new<\/strong> ComponentName(context, NormalExampleWidgetProvider.class);\n    appWidgetManager.updateAppWidget(componentName, remoteViews);\n}\n<em>\/\/ \u901a\u8fc7widgetId\u66f4\u65b0<\/em>\n<strong>public<\/strong> <strong>void<\/strong> <strong>updateWidgetByWidgetId<\/strong>(Context context, <strong>int<\/strong> widgetId) {\n    <em>\/\/ R.layout.demo_appwidget_normal_example \u4e3a\u5c0f\u90e8\u4ef6\u5e03\u5c40\u6587\u4ef6\uff0c\u8fd9\u91cc\u4ec5\u793a\u4f8b<\/em>\n    RemoteViews remoteViews = <strong>new<\/strong> RemoteViews(context.getPackageName(),\n            R.layout.demo_appwidget_normal_example);\n    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);\n    appWidgetManager.updateAppWidget(widgetId, remoteViews);\n}<\/code><\/pre>\n<h2 id=\"_26\">11.Push\u900f\u4f20\u5237\u65b0\u670d\u52a1<\/h2>\n<h3 id=\"_26_0\">11.1.\u63cf\u8ff0<\/h3>\n<p>\u5f53MIUI Widget\u72b6\u6001\u53d1\u751f\u6539\u53d8\u4e14Widget\u4e0d\u53ef\u89c1\u3001\u4e3b\u5e94\u7528\u672a\u542f\u52a8\u65f6\uff0c\u5f00\u53d1\u8005\u53ef\u8c03\u7528\u5c0f\u90e8\u4ef6\u670d\u52a1\u7aef\u63d0\u4f9b\u7684\u66f4\u65b0API\uff0c\u7ecf\u7531MI PUSH\u53d1\u9001\u900f\u4f20\u6d88\u606f\u7ed9\u8d1f\u4e00\u5c4f\/\u684c\u9762\u5ba2\u6237\u7aef\uff0c\u7531\u8d1f\u4e00\u5c4f\/\u684c\u9762\u62c9\u8d77Widget\u72ec\u7acb\u8fdb\u7a0b\uff08\u4e0d\u5524\u9192\u5e94\u7528\u4e3b\u8fdb\u7a0b\uff09\uff0c\u4ee5\u5b9e\u73b0MIUI Widget\u5b9e\u65f6\u5237\u65b0\u7684\u76ee\u7684\u3002<\/p>\n<p>\u6d41\u7a0b\u56fe\uff1a<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124120834250.jpg\" alt=\"\u5c0f\u7c73MIUI\u00a0\u5c0f\u90e8\u4ef6\u7cfb\u7edf\u80fd\u529b\u8bf4\u660e\" \/><img decoding=\"async\" class=\"j-lazy\" src=\"https:\/\/www.yimenapp.com\/kb-yimen\/wp-content\/themes\/justnews\/themer\/assets\/images\/lazy.png\" data-original=\"https:\/\/kb.cdn.yimenapp.com\/yimen\/2022\/11\/20221124120834250.jpg\" alt=\"\u5c0f\u7c73MIUI\u00a0\u5c0f\u90e8\u4ef6\u7cfb\u7edf\u80fd\u529b\u8bf4\u660e\" \/><\/figure>\n<h3 id=\"_26_1\">11.2.\u63a5\u53e3\u89c4\u8303<\/h3>\n<pre class=\"wp-block-code\"><code>\u57df\u540d: https:<em>\/\/developer.assistant.miui.com<\/em>\n\u8def\u5f84: \/openapi\/widget\/{cpCode}\/refresh\n     cpCode\u503c\u7531\u5c0f\u90e8\u4ef6\u5f00\u53d1\u4eba\u5458\u63d0\u4f9b\n\u53c2\u6570\uff1a\u9700\u5305\u542bHeader\u4ee5\u53caBody<\/code><\/pre>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>Header\u53c2\u6570\u8868<\/td>\n<\/tr>\n<tr>\n<td>\u5934\u57df\u540d\u79f0<\/td>\n<td>\u63cf\u8ff0<\/td>\n<td>\u662f\u5426\u5fc5\u9009<\/td>\n<td>\u7c7b\u578b<\/td>\n<td>\u53d6\u503c\u8303\u56f4<\/td>\n<\/tr>\n<tr>\n<td>Content-Type<\/td>\n<td>\u56fa\u5b9a\u503c\uff0c\u586b<span class=\"wpcom_keyword_link\">app<\/span>lication\/json<\/td>\n<td>\u662f<\/td>\n<td>String<\/td>\n<td>application\/json<\/td>\n<\/tr>\n<tr>\n<td>app-id<\/td>\n<td>\u5728\u5c0f\u7c73\u5f00\u653e\u5e73\u53f0\u6ce8\u518c\u7684\u7a0b\u5e8f\u7f16\u53f7<\/td>\n<td>\u662f<\/td>\n<td>String<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>access-token<\/td>\n<td>\u5e94\u7528\u7ea7token(\u6821\u9a8c\u8bf7\u6c42\u6743\u9650\uff0c\u901a\u8fc7\u5e10\u53f7\u670d\u52a1\u83b7\u53d6)<\/td>\n<td>\u662f<\/td>\n<td>String<\/td>\n<td>\u6700\u5927\u957f\u5ea6:259<\/td>\n<\/tr>\n<tr>\n<td>sign<\/td>\n<td>\u7b7e\u540d\uff08\u9a8c\u8bc1\u8bf7\u6c42\u5b8c\u6574\u6027\uff0c\u4e0b\u65b9\u6709\u7b7e\u540d\u751f\u6210\u65b9\u6cd5\uff09<\/td>\n<td>\u662f<\/td>\n<td>String<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>timestamp<\/td>\n<td>\u5f53\u524d\u65f6\u95f4\u6233\uff08\u9632\u6b62\u8bf7\u6c42\u91cd\u653e\uff0c\u4f1a\u6839\u636e\u8be5\u5b57\u6bb5\u5224\u65ad\u8bf7\u6c42\u6709\u6548\u671f\uff09<\/td>\n<td>\u662f<\/td>\n<td>long<\/td>\n<td>13\u4f4d \u6beb\u79d2\u65f6\u95f4\u6233<\/td>\n<\/tr>\n<tr>\n<td>trace-id<\/td>\n<td>\u8bf7\u6c42\u7684\u552f\u4e00\u6807\u8bc6\uff08\u7528\u6765\u5b9a\u4f4d\u6bcf\u6b21\u8bf7\u6c42\uff09<\/td>\n<td>\u662f<\/td>\n<td>String<\/td>\n<td>\u53ea\u80fd\u5305\u542b\u6570\u5b57\u548c\u5927\u5c0f\u5199\u5b57\u6bcd\uff0c\u6700\u5927\u957f\u5ea664<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>Body\u53c2\u6570\u8868<\/td>\n<\/tr>\n<tr>\n<td>\u5b57\u6bb5\u540d<\/td>\n<td>\u63cf\u8ff0<\/td>\n<td>\u5fc5\u987b<\/td>\n<td>\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td>oaid<\/td>\n<td>\u8bbe\u5907oaid<\/td>\n<td>\u662f<\/td>\n<td>String<\/td>\n<\/tr>\n<tr>\n<td>widgetId<\/td>\n<td>\u8bbe\u5907 widgetId (\u5b89\u5353\u751f\u6210\u7684id)<\/td>\n<td>\u662f<\/td>\n<td>String<\/td>\n<\/tr>\n<tr>\n<td>widgetProviderName<\/td>\n<td>\u5c0f\u90e8\u4ef6providerName<\/td>\n<td>\u662f<\/td>\n<td>String<\/td>\n<\/tr>\n<tr>\n<td>extra<\/td>\n<td>\u989d\u5916\u900f\u4f20\u5230\u5c0f\u90e8\u4ef6\u5185\u5bb9<\/td>\n<td>\u5426<\/td>\n<td>String<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u83b7\u53d6access-token\uff1aaccess-token\u7684\u83b7\u53d6\u65b9\u5f0f\u8bf7\u8054\u7cfb\u76f8\u5173\u6280\u672f\u652f\u6301\u3002<\/li>\n<li>\u5904\u7406\u7b7e\u540d<\/li>\n<\/ul>\n<pre class=\"wp-block-code\"><code>\u7b7e\u540d\u751f\u6210: \n    \u5047\u8bbe: appId = \"111111111\" , \u5f53\u524d\u65f6\u95f4\u6233\u662f 1606206667013 \uff0c\u79d8\u94a5\u662f \"testSecret\"\n    step 1: \u5148\u5c06body\u8fdb\u884cmd5\uff0c\u518d\u8f6c\u5316\u4e3a16\u8fdb\u5236\u5c0f\u5199\u5b57\u7b26\u4e32\n            \u516c\u5f0f\uff1amd5Body= Lowercase(hexEncode(md5(body)))\n    step 2: \u5c06appId\u3001\u6beb\u79d2\u65f6\u95f4\u6233\u548cbody\u7684md5Body\u503c\uff0c\u6309\u7167\u53c2\u6570\u540d\u79f0\u8fdb\u884c\u5b57\u5178\u6392\u5e8f\uff0c\u7528\u2018&amp;\u2019\u8fde\u63a5\u83b7\u5f97strToDigest\n            \u5982\uff1astrToDigest=\"appId=111111111&amp;body=md5Body&amp;timestamp=1606206667013\"          \n    step 3: \u5c06\u83b7\u5f97\u5230\u7684\u6458\u8981\u5b57\u7b26\u4e32\uff08strToDigest\uff09\u8fdb\u884cHMAC_SHA_256\uff0c\u518d\u8f6c\u5316\u4e3a16\u8fdb\u5236\u5c0f\u5199\u5b57\u7b26\u4e32\u5f97\u5230\u7b7e\u540d\n            \u516c\u5f0f\uff1aLowercase(hexEncode(HMAC_SHA_256(\"testSecret\", strToDigest)))<\/code><\/pre>\n<pre class=\"wp-block-code\"><code><em>\/\/ \u7b7e\u540djava demo: <\/em>\n<em>\/\/ demo\u5f15\u7528\u4e86apache\u7684\u5de5\u5177\u7c7b\u8fdb\u884c\u5904\u7406\uff0c\u82e5\u4e0d\u60f3\u5f15\u7528\u53ef\u4ee5\u53c2\u8003\u5176\u903b\u8f91\u81ea\u884c\u5b9e\u73b0<\/em>\n&lt;!-- https:<em>\/\/mvnrepository.com\/artifact\/commons-codec\/commons-codec --&gt;<\/em>\n&lt;dependency&gt;\n    &lt;groupId&gt;commons-codec&lt;\/groupId&gt;\n    &lt;artifactId&gt;commons-codec&lt;\/artifactId&gt;\n    &lt;version&gt;1.14&lt;\/version&gt;\n&lt;\/dependency&gt;\n\n@Slf4j\n<strong>public<\/strong> <strong>class<\/strong> <strong>SignatureUtils<\/strong> {\n    \n    <em>\/**\n     * \u751f\u6210\u7b7e\u540d\n     *\n     * @param appId     \u5e94\u7528id\n     * @param secret    \u79d8\u94a5\n     * @param timestamp \u8bf7\u6c42\u7684\u65f6\u95f4\u6233\n     * @param body      \u8bf7\u6c42\u7684body\u5185\u5bb9\n     * @return \u7b7e\u540d\u4fe1\u606f\n     *\/<\/em>\n    <strong>public<\/strong> <strong>static<\/strong> String <strong>generateSignature<\/strong>(String appId, String secret, String timestamp, String body) {\n        String sign = <strong>null<\/strong>;\n        <strong>try<\/strong> {\n            String md5Body = DigestUtils.md5Hex(body);\n            Map&lt;String, String&gt; paramMap = <strong>new<\/strong> TreeMap&lt;&gt;();\n            paramMap.put(\"appId\", appId);\n            paramMap.put(\"timestamp\", timestamp);\n            paramMap.put(\"body\", md5Body);\n            String strToDigest = paramMap.entrySet().stream().map(e -&amp;gt<a href=\"https:\/\/app.applebyme.cn\/shengcheng-39.html\">\u624b\u673aapp\u751f\u6210\u5668<\/a>; e.getKey() + \"=\" + e.getValue()).collect(Collectors.joining(\"&amp;\"));\n            sign = <strong>new<\/strong> HmacUtils(HmacAlgorithms.HMAC_SHA_256, secret).hmacHex(strToDigest);\n        } <strong>catch<\/strong> (Exception e) {\n            log.error(\"generate signature exception !\", e);\n        }\n        <strong>return<\/strong> sign;\n    }\n    \n    <em>\/**\n     * \u9a8c\u8bc1\u7b7e\u540d\n     *\n     * @param appId     \u5e94\u7528id\n     * @param secret    \u79d8\u94a5\n     * @param timestamp \u8bf7\u6c42\u7684\u65f6\u95f4\u6233\n     * @param body      \u8bf7\u6c42\u7684body\u5185\u5bb9\n     * @param sign      \u8bf7\u6c42\u7684\u7b7e\u540d\n     * @return \u7b7e\u540d\u4fe1\u606f\n     *\/<\/em>\n    <strong>public<\/strong> <strong>static<\/strong> <strong>boolean<\/strong> <strong>verifySignature<\/strong>(String appId, String secret, String timestamp, String body, String sign) {\n        <strong>return<\/strong> sign.equals(generateSignature(appId, secret, timestamp, body));\n    }\n}<\/code><\/pre>\n<ul>\n<li>\u8fd4\u56de\u72b6\u6001\u7801\u5b9a\u4e49<\/li>\n<\/ul>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>\u72b6\u6001\u7801<\/td>\n<td>\u63cf\u8ff0<\/td>\n<\/tr>\n<tr>\n<td>\u6210\u529f<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>\u670d\u52a1\u5f02\u5e38<\/td>\n<td>1000<\/td>\n<\/tr>\n<tr>\n<td>\u65e0\u6548\u53c2\u6570<\/td>\n<td>1001<\/td>\n<\/tr>\n<tr>\n<td>\u7f3a\u5931\u53c2\u6570<\/td>\n<td>1002<\/td>\n<\/tr>\n<tr>\n<td>token\u9a8c\u8bc1\u5931\u8d25<\/td>\n<td>3000<\/td>\n<\/tr>\n<tr>\n<td>\u7b7e\u540d\u9a8c\u8bc1\u5931\u8d25<\/td>\n<td>4000<\/td>\n<\/tr>\n<tr>\n<td>\u6d41\u91cf\u9650\u5236<\/td>\n<td>5000<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<ul>\n<li>\u5f00\u53d1\u8005MIUI Widget\u53ef\u4ece\u5237\u65b0\u5e7f\u64ad\u7684Intent\u4e2d\u5f97\u5230extra\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<h3 id=\"_26_2\">11.3.\u793a\u4f8b<\/h3>\n<pre class=\"wp-block-code\"><code><em>\/\/ Curl\u793a\u4f8b\uff1a<\/em>\ncurl --location --request POST 'http:\/\/developer.assistant.miui.com\/openapi\/widget\/testCp\/refresh' \n    --header 'app-id: 111111111' \n    --header 'access-token: A1_oKs19iiWArgij6qFYaEAooAMqG3bhXUgS0MZQf63KQTgWju-oj9YuccqR1EhbugrqnFmooNr6mKdkfEdKN740fUYpxk0o9ZHE5QpFvR1fhaoJ7xELYD1byNnYZb-tB-y5DPXRLIp8ikod5lUZGnayuLVPePa7uB1LlVzw-qPS-U' \n    --header 'sign: 664d528f398af20f23b6e4ec43d4e9662476ee8fc9c5cee42dd897b1af0152e7' \n    --h<a href=\"https:\/\/app.applebyme.cn\/shengcheng-107.html\">\u751f\u6210\u81ea\u5df1\u7684app<\/a>eader 'timestamp: 1636341480000' \n    --header 'trace-id: 123123' \n    --header 'Content-Type: application\/json' \n    --data-raw '{\n        \"oaid\": \"f29eb7d12222fb6b\",\n        \"widgetId\": \"666\",\n        \"widgetProviderName\": \"com.miui.test\",\n        \"extra\": \"{\"test\":123}\"\n    }'<\/code><\/pre>\n<p>\u7f16\u8f91\uff1ayimen\uff0c\u5982\u82e5\u8f6c\u8f7d\uff0c\u8bf7\u6ce8\u660e\u51fa\u5904\uff1ahttps:\/\/www.yimenapp.com\/kb-yimen\/12415\/<\/p>\n<p>\u90e8\u5206\u5185\u5bb9\u6765\u81ea\u7f51\u7edc\u6295\u7a3f\uff0c\u5982\u6709\u4fb5\u6743\u8054\u7cfb\u7acb\u5220<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u7c73MIUI\u00a0\u5c0f\u90e8\u4ef6\u7cfb\u7edf\u80fd\u529b\u8bf4\u660e1.\u8c03\u8d77 MIUI Widget \u5546\u5e97\u91cc\u7684\u8be6\u60c5\u9875\uff0c\u6dfb\u52a0\u5e94\u7528\u7684 MIUI Widget1.1.\u63cf\u8ff0\u542f\u52a8 Widget \u8be6\u60c5\u9875\uff0c\u8be6\u60c5\u9875\u4f1a\u5305\u542b\u8be5 App \u901a\u8fc7\u5ba1\u6838\u7684Widget\u3002\u7528\u6237\u53ef\u4ee5\u5de6\u53f3\u6ed1\u52a8\u9884\u89c8\uff0c\u5e76\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u6dfb\u52a0\u5230\u684c\u9762\u30021.2.\u8c03\u7528\u65b9\u5f0f\u5173\u952e\u65b9\u6cd5<br \/>\nappWidgetMa<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[548,1012,1289],"class_list":["post-1976","post","type-post","status-publish","format-standard","hentry","category-appshangjia","tag-548","tag-1012","tag-1289"],"_links":{"self":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/1976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/comments?post=1976"}],"version-history":[{"count":0,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/posts\/1976\/revisions"}],"wp:attachment":[{"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/media?parent=1976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/categories?post=1976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/app.applebyme.cn\/cloud\/wp-json\/wp\/v2\/tags?post=1976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}