首页 > 系统 > Android > 正文

android广播的实现

2019-11-09 15:51:48
字体:
来源:转载
供稿:网友

配置广播接收者 1 在清单文件中配置(静态广播) 2 使用 java 代码 (动态广播)

<application> <receiver android:name=".MyReceiver"> <intent-filter> <action android:name="com.zking.android_recece01"/> </intent-filter> </receiver> </application> 3 发送广播发送广播创建一个包含活动名称的Intent,将它传递给sendBroadcast()。Intent i = new Intent("com.zking.android_recece01");sendBroadcast(i);**创建MyPhoneState类继承BroadcastReceiver**1 重写 onReceive() 方法,在EditText中打印intent的活动名称.**获取Activity Context 的办法**package com.hmkcode.android;import android.app.Application;public class MainActivity extends Application { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @Override public void onCreate() { super.onCreate(); }}ReceiverResctrictredContext传递给onReceive()方法。需要获取MainActivity context
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表