Android Question Can not open downloaded file using Intent

Ganiadi

Active Member
Licensed User
Longtime User
Hi All,

I tried to download a video file, save it in a shared directory and view using Intent
But i got below error

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://com.MyTest.apps.provider/name/dummy.mp4 typ=video/mp4 flg=0x20001 }

Below is my code :

[CODE lang="b4x" title="Download & Open"]

Sub DownloadAndView(cMimeType As String, cFileUrl As String, cFileName As String)
Dim Intent1 As Intent
Dim HTTPTask As HttpJob

HTTPTask.Initialize("HTTPTask", Me)
HTTPTask.Download(cFileUrl)
wait for (HTTPTask) JobDone(HTTPTask As HttpJob)

If HTTPTask.Success Then
Try
Dim out As OutputStream = File.OpenOutput(Starter.shared, cFileName, False)
File.Copy2(HTTPTask.GetInputStream, out)
out.Close '<------ very important

Intent1.Initialize(Intent1.ACTION_VIEW, CreateFileProviderUri(Starter.shared,cFileName))
' Intent1.SetComponent("android/com.android.internal.app.ResolverActivity")
Intent1.Flags = 1
Intent1.SetType(cMimeType)
StartActivity(Intent1)
Catch
Log(LastException.Message)
End Try

End If
End Sub

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

In Starter Class
[CODE lang="b4x" title="Starter Class"]
Sub Process_Globals
'These global variables will be declared once when the application starts.
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
[/CODE]



Please Help
Tks
 
First step is to use FileProvider class.
 
Upvote 0
First step is to use FileProvider class.
Dear Erel,

Tks alot for your reference and it solved now, actually CreateFileProviderUri also is taken from the class, but currently i changed it and use the FileProvider lib
it was my fault where the parameter that i passed to the module is taken from the database and there is a space for the cFileName,. When i trimmed it it work like a charm
 
Upvote 0

Similar Threads

Back
Top