Code like this, will put the text you want to send into the body of an email message or will create a new document on Google Drive.
public void send_data()Or, you can put the text data into an attachment with something like this.
{
// Create an intent to send data out
Intent send_intent = new Intent(android.content.Intent.ACTION_SEND);
send_intent.setType("text/plain");
String data_to_send += "Sending this data string";
send_intent.putExtra(Intent.EXTRA_TEXT, data_to_send);
startActivity(send_intent);
}
public void send_data()This all works well, but when I try to open the document in google drive, I find that it isn't a native Google drive document, and the only thing I can do is view it.
{
String FILENAME = "sample.txt";
FileOutputStream fos;
try
{
// Set the file as world readable so other apps can read it.
fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE);
// Update the file and close it.
String data_to_send += "Sending this data string";
fos.write(line_to_send.getBytes());
fos.close();
} catch (IOException e ){}
// Create an intent to send data out
String full_path_file = getFilesDir()+"/"+FILENAME;
Intent send_intent = new Intent(android.content.Intent.ACTION_SEND);
send_intent.setType("text/plain");
send_intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+full_path_file));
startActivity(send_intent);
}
I will update later again if I can find a way to improve this.
No comments:
Post a Comment