How to sent a double [] array via Bluetooth BLE using intent- Android Studio (API 17)

Viewed 283

I'm working on a project with Android studio and I'm using API 17 android phone as a terget. I would like to share some parameter via Bluetooth but I'm not able to do it. Could anyone help me? I'm using intent but now I'm only able to share a text. Here my result.java file:

package com.google.android.gms.samples.vision.face.rPPG;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertiseSettings;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.ParcelUuid;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;
import com.jjoe64.graphview.series.PointsGraphSeries;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class RespirationResult extends AppCompatActivity {

    private String Date;
    int RR;
    int il_risultato;
    double [] plot_array;
    int[] intArray;


    DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    java.util.Date today = Calendar.getInstance().getTime();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_respiration_result);

        Date = df.format(today);
        TextView RRR = (TextView) this.findViewById(R.id.RRR);
        ImageButton SRR = (ImageButton)this.findViewById(R.id.SendRR);
        Bundle b = getIntent().getExtras();
        double result = b.getDouble("key");
        plot_array=b.getDoubleArray("array");


        il_risultato=(int) Math.round(result);
        RRR.setText(String.valueOf(il_risultato)); 


        GraphView graph;
        LineGraphSeries<DataPoint> series;       
        graph = (GraphView) findViewById(R.id.graphico);
        series= new LineGraphSeries<>(data());   //initializing/defining series to get the data from the method 'data()'
        graph.addSeries(series);                   //adding the series to the GraphView

        graph.getViewport().setScalableY(true);

        graph.getGridLabelRenderer().setGridColor(Color.DKGRAY);
        graph.getGridLabelRenderer().setHorizontalLabelsColor(Color.DKGRAY);
        graph.getGridLabelRenderer().setVerticalLabelsColor(Color.DKGRAY);
        graph.getGridLabelRenderer().setHorizontalAxisTitle("time(sec)");
        graph.getGridLabelRenderer().setVerticalAxisTitle("RR");

        // set manual X bounds
        graph.getViewport().setXAxisBoundsManual(true);
        graph.getViewport().setMinX(0.5);
        graph.getViewport().setMaxX(100);

        SRR.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
                sendIntent.setType("text/plain");
                startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));

            }
        });



    }


    public DataPoint[] data(){
        DataPoint[] values = new DataPoint[plot_array.length];     //creating an object of type DataPoint[] of size 'n'
        for(int i=0;i<plot_array.length;i++){
            DataPoint v = new DataPoint(i,plot_array[i]);
            values[i] = v;
        }
        return values;
    }

    @Override
    public void onBackPressed() {

        Intent i = new Intent(RespirationResult.this, SplashScreen.class);
        startActivity(i);
        finish();
        super.onBackPressed();

    }
}

I would to sent plotarray instead text. Here ther is a simple UI of my project: enter image description here

1 Answers

You can use putSerializable() for arrays.

So it will be:

Bundle bundle = new Bundle();
bundle.putSerializable("KEY", plot_array);
sentIntent.putExtras(bundle);
Related