作者:epa4316380 | 来源:互联网 | 2024-10-17 10:23
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);
}
}