Reputation: 1074
I'm developing an app that should be able to transfer simple data between devices.
So first step is to send some data from my app on Device 1 to Device 2. I'm using the code below:
Button btnShare = (Button)findViewById(R.id.btnShare);
btnShare.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Name:"+oldName+",Surname:"+oldName);
startActivity(sendIntent);
}
});
After the button click Android share menu appears and I select Bluetooth option. I use it to send data to Device 2 and it gets there as file with extension ".html".
Now I would like to open that file and use data stored inside in my app on second device. I click on file in my Bluetooth folder and I choose my app from menu with suggested apps to use with html files.
My app on second device starts but I can't get data from the file.
What is the most simple way to get data with my app from that file? Should I use ACTION_VIEW?
Upvotes: 2
Views: 151
Reputation: 8170
In the activity that is opened you need to get the data via the Intent object
Intent intent = getIntent();
Uri uri = intent.getData();
String filename = null;
if (uri!=null)
filename = uri.getPath();
Upvotes: 1