Patrick Utz
Newbie
I am in the process of creating an application that will be able to utilize WiFi Aware to communicate directly between devices (essentially the better alternative to Bluetooth). I am wondering if anyone has experience using this API as I am unable to properly implement the attach() method to start the connection. I have added my source code. Any form of help would be greatly appreciated. Thank you!
Code:
package com.patrickutz.wifiawarepublish;
import android.content.Context;
import android.net.wifi.aware.AttachCallback;
import android.net.wifi.aware.WifiAwareManager;
import android.net.wifi.aware.WifiAwareSession;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.net.wifi.aware.PublishConfig;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
AttachCallback attachCallback = new AttachCallback();
Handler handler = new Handler();
// This is where I run into issues as Android Studio does not recognize the method attach
WifiAwareSession publish = attach(attachCallback, handler);
private static final String AWARE_FILE_SHARE_SERVICE_NAME = "Test Publish";
PublishConfig config = new PublishConfig.Builder()
.setServiceName(AWARE_FILE_SHARE_SERVICE_NAME)
.build();
// Outputs the state of WifiAwareManager when press button (for now)
String state_change = WifiAwareManager.ACTION_WIFI_AWARE_STATE_CHANGED;
int data_init = WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_INITIATOR;
int data_resp = WifiAwareManager.WIFI_AWARE_DATA_PATH_ROLE_RESPONDER;
public void showStatus(View view) {
// Get the text views
TextView showStateChangeTextView = (TextView) findViewById(R.id.stateChangeTextView);
TextView showDataPathRoleInitTextView = (TextView) findViewById(R.id.dataPathRoleInitTextView);
TextView showDataPathRoleRespTextView = (TextView) findViewById(R.id.dataPathRoleRespTextView);
// Display the new values of current state in the text view.
showStateChangeTextView.setText("State: " + state_change);
showDataPathRoleInitTextView.setText("Data Initiator: " + Integer.toString(data_init));
showDataPathRoleRespTextView.setText("Data Responder: " + Integer.toString(data_resp));
}
}