{"id":42345,"date":"2023-12-11T14:56:16","date_gmt":"2023-12-11T06:56:16","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=42345"},"modified":"2023-12-11T14:56:16","modified_gmt":"2023-12-11T06:56:16","slug":"android-%e5%b9%bf%e6%92%ad%e7%9a%84%e5%88%86%e7%b1%bb%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/11\/android-%e5%b9%bf%e6%92%ad%e7%9a%84%e5%88%86%e7%b1%bb%ef%bc%9f\/","title":{"rendered":"Android \u5e7f\u64ad\u7684\u5206\u7c7b\uff1f"},"content":{"rendered":"<p>&#8220;`&#8221;                     \u5206\u4e3a\u6709\u5e8f\u5e7f\u64ad\u548c\u65e0\u5e8f\u5e7f\u64ad\u4e24\u7c7b\u3002<\/p>\n<p>\u65e0\u5e8f\u5e7f\u64ad\u53d1\u9001\u4ee3\u7801\uff1a<\/p>\n<p>&lt;pre&gt;&lt;code&gt;public class MainActivity extends Activity {<\/p>\n<p>    @Override<br \/>\n    protected void onCreate(Bundle savedInstanceState) {<br \/>\n        super.onCreate(savedInstanceState);<br \/>\n        setContentView(R.layout.activity_main);<br \/>\n    }<\/p>\n<p>    public void click(View v){<br \/>\n        \/\/\u542f\u52a8\u754c\u9762 startActivity<br \/>\n        \/\/\u53d1\u9001\u5e7f\u64ad sendBroadcast<\/p>\n<p>        Intent intent = new Intent();<\/p>\n<p>        intent.setAction(&quot;&quot;com.itheima.cctv.action.NEWS&quot;&quot;);<br \/>\n        intent.putExtra(&quot;&quot;data&quot;&quot;, &quot;&quot;\u6211\u662f\u4e00\u4e2a\u65e0\u987b\u7684\u5e7f\u64ad&quot;&quot;);<br \/>\n        sendBroadcast(intent);<br \/>\n    }<br \/>\n   }<br \/>\n}<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u65e0\u5e8f\u5e7f\u64ad\u7684\u76d1\u542c\u4ee3\u7801\uff1a<\/p>\n<p>&lt;pre&gt;&lt;code&gt;public class CctvReceiver extends BroadcastReceiver {<br \/>\n    private static final String TAG = &quot;&quot;CctvReceiver&quot;&quot;;<br \/>\n    @Override<br \/>\n    public void onReceive(Context context, Intent intent) {<br \/>\n        String data = intent.getStringExtra(&quot;&quot;data&quot;&quot;);<br \/>\n        Log.d(TAG, &quot;&quot;data===&quot;&quot;+data);<br \/>\n    }<br \/>\n}<\/p>\n<p>&lt;receiver android:name=&quot;&quot;com.itheima.cctv.CctvReceiver&quot;&quot;&gt;<br \/>\n            &lt;intent-filter &gt;<br \/>\n            &lt;!&#8211;\u8fd9\u91cc\u76d1\u542c\u7684\u5e7f\u64ad\u5c31\u662f\u4e0a\u9762\u53d1\u9001\u5e7f\u64ad\u8bbe\u7f6e\u7684                intent.setAction(&quot;&quot;com.itheima.cctv.action.NEWS&quot;&quot;);&#8211;&gt;<br \/>\n                &lt;action android:name=&quot;&quot;com.itheima.cctv.action.NEWS&quot;&quot;\/&gt;<br \/>\n            &lt;\/intent-filter&gt;<br \/>\n&lt;\/receiver&gt;<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u6709\u5e8f\u5e7f\u64ad\u53d1\u9001\uff1a<\/p>\n<p>&lt;pre&gt;&lt;code&gt;public class ShengReceiver extends BroadcastReceiver {<br \/>\n    @Override<br \/>\n    public void onReceive(Context context, Intent intent) {<br \/>\n        Log.d(&quot;&quot;vivi&quot;&quot;, &quot;&quot;\u6211\u662f\u7701\u7ea7\u90e8\u95e8\uff0c\u6211\u6536\u5230\u7684\u6307\u4ee4\u662f\uff1a&quot;&quot;+getResultData());<br \/>\n        \/\/getResultData()\u662f\u7528\u6765\u83b7\u53d6\u6709\u5e8f\u5e7f\u64ad\u91cc\u9762\u7684\u6570\u503c.\u8fd9\u91cc\u7684\u4fe1\u606f\u662f:<br \/>\n        \/\/\u4e3b\u5e2d\u8bb2\u8bdd\uff1a\u6bcf\u4eba\u5956\u52b110\u65a4\u571f\u8c46<br \/>\n            setResultData(&quot;&quot;\u4e3b\u5e2d\u8bb2\u8bdd\uff1a\u6bcf\u4eba\u5956\u52b17\u65a4\u571f\u8c46&quot;&quot;);\/\/\u6709\u5e8f\u5e7f\u64ad\u7684\u6570\u503c,\u53ef\u4ee5\u88ab\u4fee\u6539,\u540e\u9762\u7684\u7a0b\u5e8f\u5728\u63a5\u53d7\u5230\u8fd9\u4e2a\u5e7f\u64ad,\u5c31\u4f1a\u53d8\u6210,\u73b0\u5728\u6211\u4eec\u6539\u53d8\u7684\u503c\u4e86<\/p>\n<p>        \/\/\u6709\u5e8f\u5e7f\u64ad\u4f20\u8f93\u662f\u53ef\u4ee5\u7ec8\u6b62\u7684.\u4f46\u662f\u6700\u7ec8\u7684\u63a5\u53d7\u8005\u5c31\u7b97\u5728\u7ec8\u6b62\u4e4b\u540e,\u4e5f\u662f\u53ef\u4ee5\u63a5\u53d7\u5230\u6570\u636e\u7684<br \/>\n        \/\/abortBroadcast();<br \/>\n    }<br \/>\n }<\/p>\n<p>public class ShiReceiver extends BroadcastReceiver {<br \/>\n    @Override<br \/>\n    public void onReceive(Context context, Intent intent) {<br \/>\n        Log.d(&quot;&quot;vivi&quot;&quot;, &quot;&quot;\u6211\u662f\u5e02\u7ea7\u90e8\u95e8\uff0c\u6211\u6536\u5230\u7684\u6307\u4ee4\u662f\uff1a&quot;&quot;+getResultData());<br \/>\n    \/\/\u56e0\u4e3a\u4e0a\u9762\u4fee\u6539\u4e86\u6570\u636e,\u6240\u4ee5\u8fd9\u91cc\u83b7\u53d6\u5230\u7684\u6570\u636e\u662f:\u4e3b\u5e2d\u8bb2\u8bdd\uff1a\u6bcf\u4eba\u5956\u52b17\u65a4\u571f\u8c46<br \/>\n    }<br \/>\n}<br \/>\n&lt;!&#8211;\u6709\u5e8f\u5e7f\u64ad\u7684\u4f18\u5148\u7ea7\u522b\u4f7f\u7528 android:priority=&quot;&quot;&quot;&quot;\u6765\u6307\u5b9a,\u6700\u9ad8\u662f1000,\u6700\u4f4e\u662f-1000&#8211;&gt;<br \/>\n&lt;receiver android:name=&quot;&quot;com.itheima.region.ShengReceiver&quot;&quot;&gt;<br \/>\n            &lt;intent-filter android:priority=&quot;&quot;1000&quot;&quot;&gt;<br \/>\n                &lt;action android:name=&quot;&quot;com.itheima.gov.action.POTATO&quot;&quot;\/&gt;<br \/>\n            &lt;\/intent-filter&gt;<br \/>\n        &lt;\/receiver&gt;<br \/>\n &lt;receiver android:name=&quot;&quot;com.itheima.region.ShiReceiver&quot;&quot;&gt;<br \/>\n       &lt;intent-filter android:priority=&quot;&quot;500&quot;&quot;&gt;<br \/>\n            &lt;action android:name=&quot;&quot;com.itheima.gov.action.POTATO&quot;&quot;\/&gt;<br \/>\n        &lt;\/intent-filter&gt;<br \/>\n    &lt;\/receiver&gt;<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>\u00a0<\/p>\n<p> \u6709\u5e8f\u63a5\u6536\uff1a<\/p>\n<p>&lt;pre&gt;&lt;code&gt;public class MyReceiver extends BroadcastReceiver {<\/p>\n<p>    @Override<br \/>\n    public void onReceive(Context context, Intent intent) {<br \/>\n        Log.d(&quot;&quot;vivi&quot;&quot;, &quot;&quot;\u6211\u662f\u6069\u6069\u4e3b\u5e2d\u7684\u5185\u7ebf\uff0c\u6211\u6536\u5230\u7684\u6307\u4ee4\u662f\uff1a&quot;&quot;+getResultData());<br \/>\n    }<br \/>\n}<br \/>\n&lt;\/code&gt;&lt;\/pre&gt;<\/p>\n<p>&lt;pre&gt;&lt;code&gt;            &quot;&#8220;`<br \/>\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;`&#8221; \u5206\u4e3a\u6709\u5e8f\u5e7f\u64ad\u548c\u65e0\u5e8f\u5e7f\u64ad\u4e24\u7c7b\u3002 \u65e0\u5e8f\u5e7f\u64ad\u53d1\u9001\u4ee3\u7801\uff1a &lt;pre&gt;&#038;lt [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-42345","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/42345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=42345"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/42345\/revisions"}],"predecessor-version":[{"id":42346,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/42345\/revisions\/42346"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=42345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=42345"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=42345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}