cjlotz / Xamarin.Plugins

Cross platform Xamarin Plugins
MIT License
113 stars 56 forks source link

Adding attachment on Android causes Error: E/JavaBinder( 6904): !!! FAILED BINDER TRANSACTION !!! #22

Closed sparkrod closed 9 years ago

sparkrod commented 9 years ago

Running on Android 5.1.1, Google Nexus 6, Project compiled with SDK v23 (6.0). Version 2.2.1 Produces this error: E/JavaBinder( 6904): !!! FAILED BINDER TRANSACTION !!!

Simple example of what fails:

public static bool sendEmail(this IEmailTask emailTask, string to, string cc, string subject, string body, string attachment = null) {

            if (emailTask.CanSendEmail)
            {

                var emailBuilder = new EmailMessageBuilder()
                  .To(to)
                  .Cc(cc)
                  .Subject(subject)
                  .Body(body);

                if (attachment != null)
                    emailBuilder.WithAttachment(attachment);

                var email = emailBuilder.Build();

                emailTask.SendEmail(email);

                return true;
            }

            return false;
 }
sparkrod commented 9 years ago

Confirmed that this happens with the sample project as well.

sparkrod commented 9 years ago

Here's the stacktrace from logcat for the sample project: 10-22 17:44:38.912: E/DatabaseUtils(20396): Writing exception to parcel 10-22 17:44:38.912: E/DatabaseUtils(20396): java.lang.SecurityException: Permission Denial: reading com.google.android.apps.photos.contentprovider.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F179/ACTUAL/2090966317 from pid=22454, uid=10186 requires the provider be exported, or grantUriPermission() 10-22 17:44:38.912: E/DatabaseUtils(20396): at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:539) 10-22 17:44:38.912: E/DatabaseUtils(20396): at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:452) 10-22 17:44:38.912: E/DatabaseUtils(20396): at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:443) 10-22 17:44:38.912: E/DatabaseUtils(20396): at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:388) 10-22 17:44:38.912: E/DatabaseUtils(20396): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:313) 10-22 17:44:38.912: E/DatabaseUtils(20396): at android.os.Binder.execTransact(Binder.java:446) 10-22 17:44:39.071: W/SurfaceFlinger(259): couldn't log to binary event log: overflow.

cjlotz commented 9 years ago

I tried this on a 5.1.1 emulator using the sample project after updating it to run off api level 23 and everything works fine. From the exception it seems like you are missing some permissions for the type of files you are trying to attach. Make sure you have the necessary permissions to access the files you are trying to attach. Let me know if this solves your issue.

sparkrod commented 9 years ago

I believe the emulator does not enforce the same protections as the device. Sharing files between applications requires extra handling that does not exist in the Messaging plugin. See here for more details: http://developer.android.com/training/secure-file-sharing/setup-sharing.html I believe to do this right, the code should copy the files to a known folder location and you can instruct users to update their manifest to allow apps to access files in that location.

cjlotz commented 9 years ago

It's the responsibility of the application to manage the permissions and not the plugin in my opinion. The only permissions the plugin should worry about is the permission to send e-mail, sms or make a phone call. The plugin can't (and shouldn't) cater for all the possible ways that the user can work with files. The application needs to ensure that the Uri it gives for attaching a file points to a location that is accessible (i.e. first copy to external storage/downloads or whatever). This should not be the responsibility of the plugin.

sparkrod commented 9 years ago

Agreed- I see your point. You can consider this more of an issue with the sample proj.

On Oct 24, 2015, at 1:14 AM, Carel Lotz notifications@github.com wrote:

It's the responsibility of the application to manage the permissions and not the plugin in my opinion. The only permissions the plugin should worry about is the permission to send e-mail, sms or make a phone call. The plugin can't (and shouldn't) cater for all the possible ways that the user can work with files. The application needs to ensure that the Uri it gives for attaching a file points to a location that is accessible (i.e. first copy to external storage/downloads or whatever). This should not be the responsibility of the plugin.

— Reply to this email directly or view it on GitHub.