1

This is based on this post answered by Xlythe. I am also using P2P_STAR strategy and trying to transfer the file (1GB) asUri to other 2 devices but when it received in other device it is showing some KB(1.98 kb) as file size and receiving below logs in PayloadTransferUpdate.Status.IN_PROGRESS continuously.

2022-05-23 04:27:29.233 32032-32032/com.google.location.nearby.apps.rockpaperscissors I/TAG: IN_PROGRESS:
2022-05-23 04:27:30.375 32032-32032/com.google.location.nearby.apps.rockpaperscissors I/TAG: IN_PROGRESS:
2022-05-23 04:27:31.215 32032-32032/com.google.location.nearby.apps.rockpaperscissors I/Service: onEndpointFound: endpoint lostEAP0
2022-05-23 04:27:31.728 32032-32032/com.google.location.nearby.apps.rockpaperscissors I/TAG: IN_PROGRESS:
2022-05-23 04:27:32.582 32032-32032/com.google.location.nearby.apps.rockpaperscissors I/Service: onEndpointFound: endpoint found, connectingEAP0
2022-05-23 04:27:33.151 32032-32032/com.google.location.nearby.apps.rockpaperscissors I/TAG: IN_PROGRESS:
2022-05-23 04:27:33.997 32032-32032/com.google.location.nearby.apps.rockpaperscissors I/TAG: IN_PROGRESS:

Any idea why this is happening or is there any other way to send such a large file ?

I have few more doubts in that.

  1. Why always that discovery device lost the connection and again its founding the endpoint (you can check in the above log)?
  2. If we connected with internet or Wi-Fi and once file has been received by all other devices, I wanted to stopAdvertiser but its not happening as I am connected with internet or Wi-Fi, which means Bluetooth is always enabled. So my doubt is if device is connected with local Wi-Fi or internet, nearby connection api will never call stopAdvertiser/stoDiscovery ?

Note - I have tried to send some KB file which works perfectly.

Below is my code:

public static final PayloadCallback payloadCallback = new PayloadCallback() {
        @Override
        public void onPayloadReceived(String endpointId, Payload payload) {
            Log.i(TAG,"onPayloadReceived");
            if (payload.getType() == Payload.Type.FILE){
                Uri uri = payload.asFile().asUri();
                Log.d(TAG,"received uri: " + uri);
                try {
                    // Copy the file to a new location.
                    InputStream in = mContext.getContentResolver().openInputStream(uri);
                    copyStream(in, new FileOutputStream(new File(Environment.getExternalStorageDirectory().toString()+"/Download/",fileName)));
                    Toast.makeText(mContext,"File has been received successfully", Toast.LENGTH_LONG).show();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void onPayloadTransferUpdate(String endpointId, PayloadTransferUpdate update) {
            switch(update.getStatus()){
                case PayloadTransferUpdate.Status.SUCCESS:
                    Log.i(TAG,"Successfully send the file: " + update.getStatus());
                    break;
                case  PayloadTransferUpdate.Status.FAILURE:
                    Log.i(TAG,"Failed:");

                    break;

                case PayloadTransferUpdate.Status.CANCELED:
                    Log.i(TAG,"CANCELED:");
                    break;

                case PayloadTransferUpdate.Status.IN_PROGRESS:
                    Log.i(TAG,"IN_PROGRESS:");
                    break;
            }
        }
    };
Anand
  • 4,355
  • 2
  • 35
  • 45
Priyanka
  • 11
  • 2

0 Answers0