Android Question Service Contenxt Error at CreateFileProviderUri

Kiran Raotole

Active Member
Licensed User
This Code run perfectly when call from activity.

CreateFileProviderUri:
Sub CreateFileProviderUri (Dir As String, FileName As String) As Object
    Log(Dir & " : " & FileName)
    Dim FileProvider As JavaObject
    Dim context As JavaObject
    context.InitializeContext
    FileProvider.InitializeStatic("android.support.v4.content.FileProvider")
    Dim f As JavaObject
    f.InitializeNewInstance("java.io.File", Array(Dir, FileName))
    Return FileProvider.RunMethod("getUriForFile", Array(context, Application.PackageName & ".provider", f))
End Sub

But when call from Service Its show error.
Error:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.startActivity(android.content.Intent)' on a null object reference
    at com.madelephantstudios.MESShareLibrary.MESShareLibrary.sharebinary(MESShareLibrary.java:28)
    at com.ctron.mobile.f1._share_pdf_file(f1.java:1327)
    at com.ctron.mobile.f1._item_voucher_pdf(f1.java:8970)
    at com.ctron.mobile.httpservice$ResumableSub_OpenOnlineOfflineVoucherPDF.resume(httpservice.java:555)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6762)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…