0

TargetSDK 23, Titanium SDK 5.4.0

Permissions set:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

I take a Screenshot of a view by writing it to a file. That worked, because I can add this file to an imageview and see the image.

var blob = masterView.views[currentSavedPage].toImage();
    var file = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory, "myNewImage.jpg");
    file.write(blob);

As I try to share the image with additional text, the other App (Facebook, Whatsapp, ...) can't access the image.

intent = Ti.Android.createIntent({
            action : Ti.Android.ACTION_SEND,
            type : "image/jpeg"
        });
        intent.putExtra(Ti.Android.EXTRA_TEXT, text);
        intent.putExtra(Ti.Android.EXTRA_SUBJECT, subject);
        intent.putExtraUri(Ti.Android.EXTRA_STREAM, file.nativePath);
        share = Ti.Android.createIntentChooser(intent, 'Bild teilen');

I only got a Permission denied as Error and don't know how to fix this. This worked with an lower SDK Version.

fb4a.RequestLoggingListener: java.io.FileNotFoundException: /data/user/0/de.myapp.id/app_appdata/myNewImage.jpg: open failed: EACCES (Permission denied)
ExifInterface: java.io.FileNotFoundException: /data/user/0/de.myapp.id/app_appdata/myNewImage.jpg: open failed: EACCES (Permission denied)
BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /data/user/0/de.myapp.id/app_appdata/myNewImage.jpg: open failed: EACCES (Permission denied)

Solution:

if (!Ti.Filesystem.hasStoragePermissions()) {
  Ti.Filesystem.requestStoragePermissions(function(result) {
    if (result.success) {
      openShareIntent();
    } else {
      alert('Permissions denied.');
    }
  });
} else {
  openShareIntent();
}

2 Answers2

1

If it's not already did :

Try to go to your settings->Application->YourApp; then click permission and authorize access to storage.

But you should ask the permission directly from the app. The exemple of the official doc is simple : https://developer.android.com/training/permissions/requesting.html

BaptisteM
  • 147
  • 1
  • 12
  • 1
    Have a look at https://github.com/appcelerator-developer-relations/appc-sample-ti510/blob/master/app/controllers/permissions.js for a full example of how to get these permission in Titanium. But to test it you can change the settings inside the app info as recommended above – miga Jul 19 '17 at 14:32
1

You need to implement runtime permissions for Android 6.0 and above. As it does not have the permission, even though defined in the manifest or tiapp.xml. Provide runtime permission and it should not give permission errors.

Soumya
  • 1,350
  • 3
  • 19
  • 34