Example usage for android.net.wifi.p2p WifiP2pConfig WifiP2pConfig

List of usage examples for android.net.wifi.p2p WifiP2pConfig WifiP2pConfig

Introduction

In this page you can find the example usage for android.net.wifi.p2p WifiP2pConfig WifiP2pConfig.

Prototype

public WifiP2pConfig() 

Source Link

Usage

From source file:com.alanddev.gmscall.fragment.DeviceDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mContentView = inflater.inflate(R.layout.device_detail, null);
    mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {

        @Override/* w  ww.  j a  v a 2s  .c o  m*/
        public void onClick(View v) {
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                    "Connecting to :" + device.deviceAddress, true, true
            //                        new DialogInterface.OnCancelListener() {
            //
            //                            @Override
            //                            public void onCancel(DialogInterface dialog) {
            //                                ((DeviceActionListener) getActivity()).cancelDisconnect();
            //                            }
            //                        }
            );
            ((DeviceListFragment.DeviceActionListener) getParentFragment()).connect(config);

        }
    });

    mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((DeviceListFragment.DeviceActionListener) getParentFragment()).disconnect();
        }
    });

    mContentView.findViewById(R.id.btn_start_client).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Allow user to pick an image from Gallery or other
            // registered apps
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");
            startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
        }
    });

    return mContentView;
}

From source file:com.example.healthplus.wifidirect.DeviceDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mContentView = inflater.inflate(R.layout.device_detail, null);
    mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {

        @Override//from   w ww  . jav a2s.c om
        public void onClick(View v) {
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                    "Connecting to :" + device.deviceAddress, true, true
            //                        new DialogInterface.OnCancelListener() {
            //
            //                            @Override
            //                            public void onCancel(DialogInterface dialog) {
            //                                ((DeviceActionListener) getActivity()).cancelDisconnect();
            //                            }
            //                        }
            );
            ((DeviceActionListener) getActivity()).connect(config);

        }
    });

    mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((DeviceActionListener) getActivity()).disconnect();
        }
    });

    mContentView.findViewById(R.id.btn_start_client).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Allow user to pick an image from Gallery or other
            // registered apps
            //Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            //Log.d(WiFiDirectActivity.TAG, "Reached here Richa1");
            //intent.setType("image/*");
            //intent.setType("text/plain");
            //startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
            //Log.d(WiFiDirectActivity.TAG, "Reached here Richa2");
            sendFile();

        }
    });

    return mContentView;
}

From source file:com.example.android.wifidirect.DeviceDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mContentView = inflater.inflate(R.layout.device_detail, null);
    mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {

        @Override//from w ww . j  a  v a  2s  . c o m
        public void onClick(View v) {
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                    "Connecting to :" + device.deviceAddress, true, true
            //                        new DialogInterface.OnCancelListener() {
            //
            //                            @Override
            //                            public void onCancel(DialogInterface dialog) {
            //                                ((DeviceActionListener) getActivity()).cancelDisconnect();
            //                            }
            //                        }
            );
            ((DeviceActionListener) getActivity()).connect(config);

        }
    });

    mContentView.findViewById(R.id.btn_send_data);

    mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((DeviceActionListener) getActivity()).disconnect();
        }
    });

    mContentView.findViewById(R.id.btn_start_client).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Allow user to pick an image from Gallery or other
            // registered apps
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");
            startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
        }
    });

    return mContentView;
}

From source file:it.polimi.wifidirect.DeviceDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mContentView = inflater.inflate(R.layout.device_detail, container, false);

    this.updateThisDevice();

    //click connect's button
    mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {

        @Override/*from  www .j  av  a2 s.  c o  m*/
        public void onClick(View v) {
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.getP2pDevice().deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                    "Connecting to :" + device.getP2pDevice().deviceAddress, true, true);
            ((DeviceListFragment.DeviceActionListener) getActivity()).connect(config);

        }
    });

    mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ClientList.getInstance().getList().clear();
            ((DeviceListFragment.DeviceActionListener) getActivity()).disconnect();
        }
    });

    mContentView.findViewById(R.id.btn_start_client).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Allow user to pick an image from Gallery or other
            // registered apps
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("video/*, image/*");
            startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
        }
    });

    //click on connect's button
    mContentView.findViewById(R.id.btn_start_ping_pong).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PingPongDialog pingPongDialog = (PingPongDialog) getFragmentManager()
                    .findFragmentByTag("pingPongDialog");

            if (pingPongDialog == null) {
                pingPongDialog = PingPongDialog.newInstance();

                pingPongDialog.setTargetFragment(fragment, PINGPONG);

                pingPongDialog.show(getFragmentManager(), "pingPongDialog");
                getFragmentManager().executePendingTransactions();
            }
        }
    });

    mContentView.findViewById(R.id.btn_start_ping_pong).setVisibility(View.GONE);

    RecyclerView mRecyclerView = (RecyclerView) mContentView.findViewById(R.id.clientRecyclerView);

    LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);

    // allows for optimizations if all item views are of the same size.
    mRecyclerView.setHasFixedSize(true);

    mAdapter = new WiFiDetailClientListAdapter();
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    return mContentView;
}

From source file:com.example.swiftdatahop.Fragment_PeerDetails.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Log.d(TAG, "oncreateview attempted");
    mContentView = inflater.inflate(R.layout.tdf_peerdetails, null);

    // Show the dummy content as text in a TextView.
    if (mItem != null) {
        ((TextView) mContentView.findViewById(R.id.task_detail)).setText(mItem.content);
    }// w  w  w.ja  v a  2s.  c  o  m

    mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.d(TAG, "onclick connect attempted");
            if (device == null)
                return; //todo - add code to remove connect/disconnect button if no device
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                    "Connecting to :" + device.deviceAddress, true, true);
            ((DeviceActionListener) getActivity()).connect(config);

        }
    });

    mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((DeviceActionListener) getActivity()).disconnect();
        }
    });

    mContentView.findViewById(R.id.btn_send_file).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (info != null)
                sendFile(info);
        }
    });

    mContentView.findViewById(R.id.btn_receive_file).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            receiveFile();
        }
    });

    mContentView.findViewById(R.id.btn_set_upstream_device).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (device == null) {
                Log.e("TaskDetailFragment_PeerDetails", "Set upstream device failed with null device");
                return;
            }
            WifiP2pDevice downstream = mAppData.getDownStreamDevice();
            if (downstream != null) {
                if (downstream.deviceName.equals(device.deviceName)) {
                    Log.e("TaskDetailFragment_PeerDetails",
                            "Upstream device chosen, matches downstream device " + downstream.deviceName);
                    showToastShort("Warning: upstream device chosen, matches downstream device "
                            + downstream.deviceName);
                }
            }
            mAppData.setUpStreamDevice(device);
            Log.d("TaskDetailFragment_PeerDetails", "Upstream device set " + device.deviceName);
            showToastShort("Upstream device set " + device.deviceName);
        }
    });

    mContentView.findViewById(R.id.btn_set_downstream_device).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (device == null) {
                Log.e("TaskDetailFragment_PeerDetails", "Set downstream device failed with null device.");
                return;
            } else {
                WifiP2pDevice upStream = mAppData.getUpStreamDevice();
                if (upStream != null) {
                    if (upStream.deviceName.equals(device.deviceName)) {
                        Log.e("TaskDetailFragment_PeerDetails",
                                "Downstream device chosen, matches downstream device " + upStream.deviceName);
                        showToastShort("WARNING: Downstream device chosen, matches upStream device "
                                + upStream.deviceName);
                    }
                }
                mAppData.setDownStreamDevice(device);
                showToastShort("Downstream device set.");
                Log.d("TaskDetailFragment_PeerDetails", "Downstream device set " + device.deviceName);
            }
        }
    });

    return mContentView;
}

From source file:com.material.katha.wifidirectmp3.DeviceDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    filelist();/*from   www  . j ava 2 s. c  o m*/
    FileInputStream inputStream = null;
    try {
        inputStream = getActivity().openFileInput("myfile");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
    mContentView = inflater.inflate(R.layout.device_detail, null);
    Log.d("katha", "2");
    mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {

        //  @Override
        public void onClick(View v) {

            s_count = 0;
            c_count = 0;
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                    "Connecting to :" + device.deviceName, true, true);
            //
            // new DialogInterface.OnCancelListener() {
            //
            //                            @Override
            //                            public void onCancel(DialogInterface dialog) {
            //                                ((DeviceActionListener) getActivity()).cancelDisconnect();
            //                            }
            //                        }
            devicename = device.deviceName;
            Toast.makeText(getActivity(), devicename, Toast.LENGTH_LONG).show();
            ((DeviceListFragment.DeviceActionListener) getActivity()).connect(config);

        }
    });

    mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((DeviceListFragment.DeviceActionListener) getActivity()).disconnect();
            s_count = 0;
            c_count = 0;
            DeviceListFragment.state = "avail";
        }
    });

    mContentView.findViewById(R.id.btn_resume).setClickable(false);

    mContentView.findViewById(R.id.btn_resume).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (pause % 2 == 0) {
                pause++;
                Toast.makeText(getActivity(), "Paused !!!", Toast.LENGTH_SHORT).show();
                Button b = (Button) v.findViewById(R.id.btn_resume);
                b.setClickable(false);
                b.setVisibility(View.GONE);
                b.setText("Resume");
            } else {
                pause++;
                pd.show();
                Toast.makeText(getActivity(), "Resumed !!!", Toast.LENGTH_SHORT).show();
                Button b = (Button) v.findViewById(R.id.btn_resume);
                b.setClickable(false);
                b.setVisibility(View.GONE);
                b.setText("Resume");
            }

        }
    });

    mContentView.findViewById(R.id.btn_start_client).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            //
            // Allow user to pick an image from Gallery or other
            //                        // registered apps
            //                        /////////////////////////////////
            //                        ContentResolver cr = getActivity().getContentResolver();
            //                        InputStream is = null;
            //                        int fsize = 0;
            ////                        try {
            ////                            is=cr.openInputStream(Uri.parse(new File("/data/data/com.material.katha.wifidirectmp3/app_Shared/Screenshot_2016-04-11-08-25-12.png").toString()));
            ////                            // is = cr.openInputStream(uri);
            ////                            fsize = is.available();
            ////
            ////                            // Log.d(WiFiDirectActivity.TAG,"File size is:"+is.available()+"               "+f.getName()+"uri  "+uri + "f  "+ f+ "file name " +f.getName());
            ////                        } catch (FileNotFoundException e) {
            ////                            e.printStackTrace();
            ////                        } catch (IOException e) {
            ////                            e.printStackTrace();
            ////                        }
            //
            //                        //Log.d("katha", fileext + "fileext");
            //                        //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;change fileext = abc.substring(abc.lastIndexOf('.'));
            //
            //           /*progressDialog = new ProgressDialog(getActivity());
            //           progressDialog.setMessage("Sending file:"+abc);
            //           progressDialog.show();
            //           */
            //
            //                        // progressDialog = ProgressDialog.show(getActivity(), "Sending","Copying file :" + fileext, true, true);
            //                        // makeText(getActivity(), fileext, LENGTH_LONG).show();
            //                        TextView statusText = (TextView) mContentView.findViewById(R.id.status_text);
            //                        //  statusText.setText("Sending: " + uri);
            //                        // String devicename = "abc";
            //                        devicename = device.deviceName;
            //                        // Toast.makeText(getActivity(),devicename,Toast.LENGTH_LONG).show();
            //
            //                       // Log.d("WiFiDirectActivity", "Intent----------- " + Uri.parse(new File("DCIM/Camera/IMG_20160118_090231.jpg").toString()));
            //                        Intent serviceIntent = new Intent(getActivity(), FileTransferService.class);
            //                        serviceIntent.setAction(FileTransferService.ACTION_SEND_FILE);
            //                        //Log.d("WiFiDirectActivity", "Action" + FileTransferService.ACTION_SEND_FILE + "\n\n\n\n");
            //                        ////////////////////serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH, uri.toString());
            //                        //serviceIntent.putExtra(FileTransferService.EXTRAS_FILE_PATH,"DCIM/Camera/IMG_20160118_090231.jpg");
            //
            //                        //serviceIntent.putExtra(FileTransferService.FILE_SIZE, fsize);
            //
            //                         serviceIntent.putExtra(FileTransferService.device_name,devicename);
            //                        serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_PORT, 8988);
            //                        String localip = getDottedDecimalIP(getLocalIPAddress());
            //                        Log.d("WiFiDirectActivity", "DEVICE_NAME: " + devicename);
            //                        serviceIntent.putExtra(FileTransferService.DEVICE_NAME, devicename);
            //
            //                        if (localip.equals("192.168.49.1")) {
            //                            Log.d("WiFiDirectActivity", "Flag is 0.");
            //                            //  devicename = device.deviceName;
            //                            serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS, client_ip);
            //                            serviceIntent.putExtra(FileTransferService.Client_add, client_ip);
            //                            ;
            //                        } else {
            //                            Log.d("WiFiDirectActivity", "Flag is 1.");
            //                            //devicename = device.deviceName;
            //                            // Toast.makeText(getActivity(),devicename,Toast.LENGTH_LONG).show();
            //                            serviceIntent.putExtra(FileTransferService.EXTRAS_GROUP_OWNER_ADDRESS,
            //                                    info.groupOwnerAddress.getHostAddress());
            //                            serviceIntent.putExtra(FileTransferService.Client_add, localip);
            //
            //                        }
            //                        getActivity().startService(serviceIntent);
            //                        Log.d("WiFiDirectActivity","here");

            //////////////////////////////////
            if (!info.groupOwnerAddress.getHostAddress().equals("")) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("*/*");
                startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
            }

        }
    });

    return mContentView;
}

From source file:com.github.peejweej.androidsideloading.fragments.DeviceDetailFragment.java

private void connect() {

    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;//from   www .j  a  v a 2  s  . c o m
    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();
    }
    progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
            "Connecting to :" + device.deviceAddress, true, true
    //                        new DialogInterface.OnCancelListener() {
    //
    //                            @Override
    //                            public void onCancel(DialogInterface dialog) {
    //                                ((DeviceActionListener) getActivity()).cancelDisconnect();
    //                            }
    //                        }
    );
    ((DevicesListFragment.DeviceActionListener) getActivity()).connect(config);
}

From source file:org.distantshoresmedia.wifiDirect.DeviceDetailFragment.java

private void connect() {

    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = device.deviceAddress;
    config.wps.setup = WpsInfo.PBC;/*from   ww  w .j a  v  a 2  s .c  o m*/
    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();
    }
    progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
            "Connecting to :" + device.deviceAddress, true, true
    //                        new DialogInterface.OnCancelListener() {
    //
    //                            @Override
    //                            public void onCancel(DialogInterface dialog) {
    //                                ((DeviceActionListener) getActivity()).cancelDisconnect();
    //                            }
    //                        }
    );
    ((DeviceListFragment.DeviceActionListener) getActivity()).connect(config);
}

From source file:edu.nust.distributed.downloader.ClientActivity.java

public void connectToPeer(final WifiP2pDevice wifiPeer) {
    this.targetDevice = wifiPeer;

    WifiP2pConfig config = new WifiP2pConfig();
    config.groupOwnerIntent = 0;/*w  w  w. j  a  va2s  . co m*/
    config.deviceAddress = wifiPeer.deviceAddress;
    wifiManager.connect(wifichannel, config, new WifiP2pManager.ActionListener() {
        public void onSuccess() {

            //setClientStatus("Connection to " + targetDevice.deviceName + " sucessful");
        }

        public void onFailure(int reason) {
            //setClientStatus("Connection to " + targetDevice.deviceName + " failed");

        }
    });

}

From source file:edu.pdx.cs410.wifi.direct.file.transfer.ClientActivity.java

public void connectToPeer(final WifiP2pDevice wifiPeer) {
    this.targetDevice = wifiPeer;

    WifiP2pConfig config = new WifiP2pConfig();
    config.deviceAddress = wifiPeer.deviceAddress;
    wifiManager.connect(wifichannel, config, new WifiP2pManager.ActionListener() {
        public void onSuccess() {

            //setClientStatus("Connection to " + targetDevice.deviceName + " sucessful");
        }/*from   ww  w.j av  a2 s.  co  m*/

        public void onFailure(int reason) {
            //setClientStatus("Connection to " + targetDevice.deviceName + " failed");

        }
    });

}