Marcin Marcin - 27 days ago 14
Android Question

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

Answer

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);