Android Question [Solved] File sharing problems from your app with File Provider with Samsung S7 (Sdk24)

Star-Dust

Expert
Licensed User
Longtime User
I followed Erel's precious instructions to use the FileProvider as I updated my Apps for Android 7

It works well, I tried on my 2 devices with Android 7 .... unfortunately ... a user of mine who owns a Samsung S7 with Android 7 has problems.
As soon as you try to share a file, the app stops responding.

Unfortunately with the Samsung devices I have always had problems, but I do not think it's just bad luck.

I attach a device image as soon as I try to share a file. (the user sent it to me)
 

Attachments

  • Screenshot_20171228-100355.png
    Screenshot_20171228-100355.png
    298.2 KB · Views: 200

DonManfred

Expert
Licensed User
Longtime User
It does work on my S7 EDGE without problem. I installed the fileprovider app. then i changed to googlemail and created a mail adding an attachment i got from the b4a app...
The mail arrived successfully including the attachment.
You need to check the log.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Google send me this

Samsung Galaxy S7 Edge (hero2lte), 4096MB RAM, Android 7.0
Rapporto 1 di 4

java.lang.RuntimeException:
at anywheresoftware.b4a.AbsObjectWrapper.getObject (AbsObjectWrapper.java:50)
at anywheresoftware.b4a.keywords.StringBuilderWrapper.Append (StringBuilderWrapper.java:53)
at it.tecnomedia.primanota.starter._application_error (starter.java:153)
at java.lang.reflect.Method.invoke (Native Method)
at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:186)
at anywheresoftware.b4a.keywords.Common.CallSub4 (Common.java:1038)
at anywheresoftware.b4a.keywords.Common.CallSubNew3 (Common.java:1001)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.handleUncaughtException (ServiceHelper.java:135)
at java.lang.reflect.Method.invoke (Native Method)
at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:212)
at it.tecnomedia.primanota.main$HandleKeyDelayed.runDirectly (main.java:228)
at it.tecnomedia.primanota.main$HandleKeyDelayed.run (main.java:225)
at android.os.Handler.handleCallback (Handler.java:751)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6692)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1358)
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
It does work on my S7 EDGE without problem.
I had 4 error reports.
1 Samsung S7
1 Samsung J7
2 Huawei MediaPad M3

I own a Huawei Mediapad M3 but it works well ... for I can not deny that the error happened to my users :(:(:(
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Looks like the crash comes from the Application_Error sub.... You can not add a file to an email here. The app is crashed.
You need provide more informations. An exasmple app which shoes the issue for ex.

I'm not able to replicate the problem. I only have user messages and google reporting.
Now you pointed out to me that the error is in the stater module. I attach the form here, maybe someone notices an error.

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private logs As StringBuilder
    Private logcat As LogCat
    Private const emailAddress As String = "[email protected]"
    
    Public rp As RuntimePermissions
    Public shared As String
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    shared = rp.GetSafeDirDefaultExternal("shared")
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    'wait for 500ms to allow the logs to be updated.
    Dim jo As JavaObject
    Dim l As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
    logcat.LogCatStop
    logs.Append(StackTrace).Append(CRLF).Append(Error)
    Dim email As Email
    email.To.Add(emailAddress)
    email.Subject = "Primanota Pro - crashed"
    email.Body = logs
    StartActivity(email.GetIntent)
    'ToastMessageShow("APP CRASHED" & CRLF & " send email to developer",FALSE)
    Return True
End Sub

Sub Service_Destroy

End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I solved the first mister. The error on the Starter service. The StringBuilder object generates an error.
When Application_Error is called, a second error is generated by StringBuilder and it only signals this second error.

Now I changed StringBuilder to String. I hope to receive the actual error that is generated in the Samsung
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Still the problem is present, on some users. The anomalous thing is that it is not present on all users. Only to users who use Samsung S7, A5, J5.

Unfortunately I can no longer send ANR reports and I can not understand how to diagnose the error.
It seems that it hangs, open the window for reporting the Runtime Error, send and nothing comes to me.
:(:(:(
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
As I explained above, I entered the error handling with the stater service, but StringBuilder went into error, so I get the error generated by Application_Error in the stack tracer that I attached in the first post. But I did not get the error caused by sharing.

I removed StringBuilder and replaced with string. By doing the tests on my device now Apllication_Error does not generate an error. I have asked users of my App to send me new error reports using the sharing function. They did but now I do not get any error reports.

Now I use this:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private logs As String
    Private logcat As LogCat
    Private const emailAddress As String = "[email protected]"   
End Sub

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    'wait for 500ms to allow the logs to be updated.
    Dim jo As JavaObject
    Dim l As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
    logcat.LogCatStop
    logs = StackTrace & CRLF & Error
    Dim email As Email
    email.To.Add(emailAddress)
    email.Subject = "Primanota Pro - crashed"
    email.Body = logs
    StartActivity(email.GetIntent)
   
    Return True
End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
This is all
B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private logs As String
    Private logcat As LogCat
    Private const emailAddress As String = ""  
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    'wait for 500ms to allow the logs to be updated.
    Dim jo As JavaObject
    Dim l As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
    logcat.LogCatStop
    logs = StackTrace & CRLF & Error
    Dim email As Email
    email.To.Add(emailAddress)
    email.Subject = "Primanota Pro - crashed"
    email.Body = logs
    StartActivity(email.GetIntent)
   
    Return True
End Sub

Sub Service_Destroy

End Sub
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I made the changes in the example. When the user tries to share a file, he generates an error.

To me Goggle sent this report:
java.lang.RuntimeException:
at anywheresoftware.b4a.AbsObjectWrapper.getObject (AbsObjectWrapper.java:50)
at anywheresoftware.b4a.keywords.StringBuilderWrapper.Append (StringBuilderWrapper.java:53)
at it.tecnomedia.primanotapro.starter._application_error (starter.java:151)
at java.lang.reflect.Method.invoke (Native Method)
at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:186)
at anywheresoftware.b4a.keywords.Common.CallSub4 (Common.java:1038)
at anywheresoftware.b4a.keywords.Common.CallSubNew3 (Common.java:1001)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.handleUncaughtException (ServiceHelper.java:135)
at java.lang.reflect.Method.invoke (Native Method)
at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:212)
at anywheresoftware.b4a.BA.raiseEvent (BA.java:166)
at anywheresoftware.b4a.phone.Phone$LogCat$1.run (Phone.java:751)
at java.lang.Thread.run (Thread.java:776)

Which then is the same as before
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private logs As StringBuilder
    Private logcat As LogCat
    Private const emailAddress As String = "[email protected]"   
End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    logs.Initialize
    #if RELEASE
        logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
    #end if
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

Private Sub logcat_LogCatData (Buffer() As Byte, Length As Int)
    logs.Append(BytesToString(Buffer, 0, Length, "utf8"))
    If logs.Length > 5000 Then
        logs.Remove(0,logs.Length - 4000)
    End If
End Sub


'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    'wait for 500ms to allow the logs to be updated.
    Dim jo As JavaObject
    Dim l As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
    logcat.LogCatStop
    logs.Append(StackTrace).Append(CRLF).Append(Error)
    
    Dim email As Email
    email.To.Add(emailAddress)
    email.Subject = "Primanota Pro - crashed"
    email.Body = logs
    StartActivity(email.GetIntent)
    Return True
End Sub

Sub Service_Destroy

End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I do not know what to say, this is the last error code received yesterday, after the update.

Now I'm thinking about handling the error with Try Catch since I know at what point in the code there is file sharing, and where I assume the error is born.

I will try to capture the error like that and I will work on it.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Well the problem seems to be solved, I simply added a sleep before sharing is all settled

Now I had to change the code to add a sleep and everything works properly

However, I do not report an error with Application_Error
:(
 
Upvote 0
Top