简体   繁体   English

Appcelerator:将特定视图的屏幕快照共享为“文件原因许可被拒绝”消息

[英]Appcelerator: Share Screenshot of a specific view as a File cause Permission denied message

TargetSDK 23, Titanium SDK 5.4.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. 那行得通,因为我可以将此文件添加到imageview并查看图像。

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. 当我尝试与其他文本共享图像时,其他应用程序(Facebook,Whatsapp等)无法访问该图像。

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. 这与较低的SDK版本一起使用。

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

If it's not already did : 如果尚未完成:

Try to go to your settings->Application->YourApp; 尝试转到设置->应用程序-> 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 官方文档的示例很简单: https//developer.android.com/training/permissions/requesting.html

You need to implement runtime permissions for Android 6.0 and above. 您需要为Android 6.0及更高版本实现运行时权限。 As it does not have the permission, even though defined in the manifest or tiapp.xml. 由于它没有权限,即使在清单或tiapp.xml中定义也是如此。 Provide runtime permission and it should not give permission errors. 提供运行时权限,并且不应给出权限错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM