热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Android开发新建一个类继承BroadcastReceiver

publicclassWiFiDirectBroadcastReceiverextendsBroadcastReceiver{privateWifiP2pManagermanage

public class WiFiDirectBroadcastReceiver extends BroadcastReceiver {
private WifiP2pManager manager;
private Channel channel;
private WiFiDirectActivity activity;
public WiFiDirectBroadcastReceiver(WifiP2pManagermanager, Channel channel,
WiFiDirectActivity activity) {
super();
this.manager = manager;
this.channel = channel;
this.activity = activity;
}
@Override
public void onReceive(Context context, Intent intent) {
//添加实际处理代码
}
}

首先,WiFiDirectBroadcastReceiver继承于BroadcastReceiver,需要有onReceive方法的执行。

其次,需要对函数WiFiDirectBroadcastReceiver进行定义,函数定义中通过自定义参数,方便实例化过程中将activity中的必要参数传递进来

新建一个class执行callback时也具有类似的方法

例如:

public class Beamsend implements CreateNdefMessageCallback,
OnNdefPushCompleteCallback {
NfcAdapter mNfcAdapter;
Beam activity;
public Beamsend(NfcAdapter mNfcAdapter, Beam activity){
super();
this.mNfcAdapter = mNfcAdapter;
this.activity = activity;// Register callback to set NDEF message

mNfcAdapter.setNdefPushMessageCallback(this, activity);
// Register callback to listen for message-sent success
mNfcAdapter.setOnNdefPushCompleteCallback(this, activity);
}
}


推荐阅读
author-avatar
epa4316380
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有