Marcin
Marcin

Reputation: 37

Share files with appcelerator using android intent

I try to share an file I downloaded. I put that file in the Ti.Filesystem.externalStorageDirectory. The file is saved correctly since i can show it in an ImageView.image.

Here's the code I use to start a android share intent: (apparently you can not use the file:// scheme with android API 24. See this post: stackoverflow)

filePath = filePath.replace('file','content');
var intent = Ti.Android.createIntent({
    action: Ti.Android.ACTION_SEND,
});
intent.putExtraUri(Ti.Android.EXTRA_STREAM, filePath);
$.FileList.activity.startActivity(intent);

What happens is, the share dialog opens, I choose the app I wish to share to, but then I get a notice there is nothing to share.

Screenshot of failed notification: screenshot of failed notification

Upvotes: 1

Views: 647

Answers (2)

Marcin
Marcin

Reputation: 37

actually it was quite simple:

  1. appcelerator handles the filePath by itself, so it is not necessary to replace file with content
  2. the intent needs a type parameter.

the working code would be:

var intent = Ti.Android.createIntent({
  action: Ti.Android.ACTION_SEND,
  type: '*/*'
});
intent.putExtraUri(Ti.Android.EXTRA_STREAM, filePath);
$.FileList.activity.startActivity(intent);

Upvotes: 0

Alex Cruz
Alex Cruz

Reputation: 11

try with this:

var Blob = $.container.toImage();
var file = Ti.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory, 'image_1.png');
f.write(Blob);


/// NOT HERE --filePath = filePath.replace('file','content');
var intent = Ti.Android.createIntent({
    action: Ti.Android.ACTION_SEND
});
intent.putExtraUri(Ti.Android.EXTRA_STREAM, f.filePath);
////$.FileList.activity.startActivity(intent);
Ti.Android.currentActivity.startActivity(intent);

Upvotes: 1

Related Questions