Open file from network drive

Stulish

Active Member
Licensed User
Longtime User
Hi all,

i have been playing with the SMB lib and trying to make a basic explorer program (i have attached a zip).

the file now seems to work really well and displays the correct icon depending on file type along with the name of the file also showing file size and date last modified.

The network path is displayed at the top of the screen and to go back use the back button on the phone/tablet.

I have now tried to get the app to open when a file is clicked the code snipped to open the file is below (inside the files_TtemClick subroutine):

B4X:
   Dim i As Intent 
      i.Initialize(i.ACTION_VIEW,Value)
      i.SetType(fileInf.GetFileType(Value))   
      StartActivity(i)

i get the following error:

An error has occured in sub:main_files_itemclick (java line:388)
android.content.ActivityNotFoundException: No Activity found to handle Intent {act=android.intent.action.VIEW dat=smb://networkdrive/2TB Network Drive/DefaultPicture.bmp type=image/x-ms-bmp flg=0x20000 }
continue?

the log can be seen below:

(ArrayList) [[name=2TB Network Drive/, IsInitialized=false, size=0


, date=0, dir=true], [name=IPC$/, IsInitialized=false, size=0
, date=0, dir=true]]
(ArrayList) [[name=$RECYCLE.BIN/, IsInitialized=false, size=0


, date=1341141326000, dir=true], [name=.lifeline/, IsInitialized=false, size=0
, date=1340984144000, dir=true], [name=Audio/, IsInitialized=false, size=0
, date=1310153584000, dir=true], [name=Autorun.inf, IsInitialized=false, size=25
, date=1209996858000, dir=false], [name=DefaultPicture.bmp, IsInitialized=false, size=17154
, date=1305260156000, dir=false], [name=Documents and other/, IsInitialized=false, size=0
, date=1305290174000, dir=true], [name=Downloads/, IsInitialized=false, size=0
, date=1356121555000, dir=true], [name=Icon1.ico, IsInitialized=false, size=44856
, date=1211302482000, dir=false], [name=Video/, IsInitialized=false, size=0
, date=1305290166000, dir=true]]
main_files_itemclick (java line: 388)


android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=smb://networkdrive/2TB Network Drive/DefaultPicture.bmp typ=image/x-ms-bmp flg=0x20000 }


at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1536)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1388)
at android.app.Activity.startActivityForResult(Activity.java:3252)
at android.app.Activity.startActivity(Activity.java:3359)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:670)
at lishsoft.network.media.main._files_itemclick(main.java:388)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at anywheresoftware.b4a.BA$2.run(BA.java:266)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=smb://networkdrive/2TB Network Drive/DefaultPicture.bmp typ=image/x-ms-bmp flg=0x20000 }


There is also an error when i change orientation or exit the app and then go back in, it says label or listview not initialized, but it always works on the first use. I have tried initializing the views but strange behavior happens depending on where i initialize.

Any advice would be appreciated.
 

Attachments

  • screen_shot.png
    screen_shot.png
    94.6 KB · Views: 528
  • network_explorer.zip
    59.6 KB · Views: 474
Last edited:

Stulish

Active Member
Licensed User
Longtime User
Thanks Erel,

I have tried implementing the the mime type to image/* or whatever the type is using the code below, i have also uploaded the latest zip with the code currently it still displays:

An error has occured in sub:main_files_itemclick (java line:409)
android.content.ActivityNotFoundException: No Activity found to handle Intent {act=android.intent.action.VIEW dat=smb://networkdrive/2TB Network Drive/DefaultPicture.bmp type=image/* flg=0x20000 }
continue?


B4X:
Sub Files_ItemClick (Position As Int, Value As String)
Dim fType As String, cnt As Int 
   If Value.charat(Value.Length-1)="/" Then 
      lstDir = Value 
      r = r + 1
      route.Put(r, lstDir)
         SMB1.ListFiles(lstDir,"")
         PathLab.Text = lstDir
   Else 
      Dim i As Intent 
      i.Initialize(i.ACTION_VIEW,Value)
      fType = fileInf.getfiletype(Value)
      cnt = fType.Length-1
      Do While fType.Length-1 >0 AND fType.CharAt(cnt)<>"/"
       cnt=cnt-1
      Loop 
      fType = fType.SubString2(0,cnt+1) & "*"
      i.SetType(fType)   
      StartActivity(i)
   End If
End Sub

any other idea of where i can look :)
 

Attachments

  • network_explorer v1.02.zip
    59.7 KB · Views: 395
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
Ok,

thanks erel
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
i have an android media center pen drive that connects to my network drive and will stream video, is this not possible with B4A (the only way to do it would be to download the file onto the device first).

The problem with it is i don't like the file explorer as it is not sorted and i just don't like the feel of it, thats why i wanted to try to create something

Thanks

Stu
 

Attachments

  • Android-pen.jpg
    Android-pen.jpg
    29.4 KB · Views: 346
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
I have changed the ItemClick sub routine as below:

B4X:
Sub Files_ItemClick (Position As Int, Value As String)
'If Value=".." Then                           're-add to include back button on top of listview
'   BackButton_Click
'Else 
   If Value.charat(Value.Length-1)="/" Then 
      lstDir = Value 
      r = r + 1
      route.Put(r, lstDir)
         SMB1.ListFiles(lstDir,"")
         PathLab.Text = lstDir
   Else 
          Dim i As Intent, fType As String, cnt As Int 
      
        i.Initialize(i.ACTION_VIEW,"file://" & Value)
        fType = fileInf.getfiletype(Value)
        cnt = fType.Length-1
        Do While fType.Length-1 >0 AND fType.CharAt(cnt)<>"/"
         cnt=cnt-1
        Loop 
        fType = fType.SubString2(0,cnt+1) & "*"
        i.SetType(fType)    
        StartActivity(i)      
   End If
'End If
End Sub

i added "file://" infront of the URL so it now outputs somthing like "file://smb://networkdrive/2TB Network Drive/DefaultPicture.bmp"

this now asks what app you want to use to complete the action, but once selected the app cant seem to see the file.

i selected MOBO player for a video file, but it says cant open file, i am now thinking it is the string that i use as the URL is incorrect.

again any ideas are welcome

Stu
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
the file will open from MOBO player and i have also installed file manager and file manager HD and they allow you to select the file and then it asks what app to use to play the file. if i select MOBO player then the file plays OK in MOBO player.

so at the moment i am a little stumped.

Thanks

Stu
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
Monster,

I already tried that and get the same results on all of my android devices, basically if i leave the url to start with smb:// it throws up an error, if i change it to file:// then it cant see the file but asks to open the correct application.

I must be close to the solution, its just getting there :(
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
can you post your latest project with the latest changes? Then I might have a look at it later today.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
the file will open from MOBO player and i have also installed file manager and file manager HD and they allow you to select the file and then it asks what app to use to play the file. if i select MOBO player then the file plays OK in MOBO player.

so at the moment i am a little stumped.

Thanks

Stu

Just create an intent filter and see what the file manager is sending in the intent.
Or maybe use this app: https://play.google.com/store/apps/details?id=uk.co.ashtonbrsc.android.intentintercept (open the file with this app instead of moboplayer to see the intent details)
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
@thedesolatesoul

i installed Intent Intercept and when i click on a video file or bmp (basically anything that it knows the extension for) it will ask what player to open in but doesn't give an option for it to be opened with intent intercept. i clicked on a SRT file and it didn't know what this was so it asked if it was video, picture etc, i selected video and the intent below was displayed:

file:///mnt/sdcard/.rhmsoft/fm/cache/Game%20of%20Thrones%20-%201x01%20-%20Winter%20is%20Coming.720p%20HDTV.en(1).srt

i did try changing the intent string to have %20 instead of a space, but this cause MOBO player to crash :(

@moster

I have attached the latest project for you to look at if you get a chance.

thanks for helping guys

Stu
 

Attachments

  • network_explorer v1.03.zip
    59.8 KB · Views: 371
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
@thedesolatesoul

i installed Intent Intercept and when i click on a video file or bmp (basically anything that it knows the extension for) it will ask what player to open in but doesn't give an option for it to be opened with intent intercept. i clicked on a SRT file and it didn't know what this was so it asked if it was video, picture etc, i selected video and the intent below was displayed:



i did try changing the intent string to have %20 instead of a space, but this cause MOBO player to crash :(
Thats weird. I just tried intent intercept and it shows up in the 'Open With' menu for both images and videos. Did you enable it in the app settings?

What you need to do is use ES File Explorer or File Manager HD, whichever can see the SMB directory, browse to it and open it, then it will show Intent Intercept, select that and it should give you the details of the intent (I am not at my machine or I would try it myself).

The example you gave seems to be of a local file not on the SMB server.

Also, rather than manually adding %20, you should just urlencode the string, it will do all the necessary replacements for you.
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
thedesolatesoul thanks for the help,

Yeah i enabled in settings and it does show up in the open with menu for files that are not standard files, but with video's and bmp's for example it isn't in the list of the open with menu ???

I will take a look at the urlencode options and see what it does

Regards

Stu

P.S. sorry to be a pain to everyone.
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
Guys,

just to let you know i have had some joy, looking at file manager it seemed to be copying to the local memory first, so i have changed the ItemClick routine to first download to the RootExternal directory and then send the intent pointing to the local file, this seems to be working (see code below), i will need to add a delete file on completion to tidy up, and i will have to make a directory to put the cached files into:

I will keep playing, thanks for all the help, i will keep posting updates in case anyone is interested :)

B4X:
Sub Files_ItemClick (Position As Int, Value As String)
'If Value=".." Then                           're-add to include back button on top of listview
'   BackButton_Click
'Else 
Log(Value)
   If Value.charat(Value.Length-1)="/" Then 
      lstDir = Value 
      r = r + 1
      route.Put(r, lstDir)
         SMB1.ListFiles(lstDir,"")
         PathLab.Text = lstDir
   Else 
          Dim i As Intent, fType As String, cnt As Int
      cnt=Value.Length-1
      Do While Value.CharAt(cnt)<>"/" AND cnt>0
         cnt=cnt-1
      Loop
          fType = fileInf.getfiletype(Value)
      SMB1.DownloadFile(Value.SubString2(0,cnt+1),Value.SubString(cnt+1),File.DirRootExternal, Value.SubString(cnt+1))
        i.Initialize(i.ACTION_VIEW,File.DirRootExternal & "/" & Value.SubString(cnt+1))
      If fType<>"Unknown" Then 
           cnt = fType.Length-1
           Do While fType.Length-1 >0 AND fType.CharAt(cnt)<>"/"
              cnt=cnt-1
           Loop 
           fType = fType.SubString2(0,cnt+1) & "*"
           i.SetType(fType)    
           StartActivity(i)
      End If
   End If
'End If
End Sub
 
Upvote 0

dmtulsa

Member
Licensed User
Longtime User
Stu,

I've been playing with your code here and I'm having a problem showing the directory or file icons. I get an error BitMap not Initialized

B4X:
Dim bmp As Bitmap,fileEx As String, x As Int, title As String, bFile As String, fDate As String , fSize As Double,secLine As String
Dim mySort As List

B4X:
bmp = images.Getdefault(bFile,images.Get("default"))                
Files.AddTwoLinesAndBitmap2(title,secLine,xbmp,Url & myFile.name)



I'm connecting to a win 2003 server and get to the directories & files ok. It's funny I just started the same kind of program last Friday and then saw you post yesterday. You a little ahead of me.

Doug
 
Upvote 0

Stulish

Active Member
Licensed User
Longtime User
Doug,

I dont get a bmp error, the only error i get is it saying label not initialized (whenever i change orientation).

I will have a look into it when i get a chance over the next couple of days. i have added my latest version to this post (not sure what version you were looking at) this includes all the picture files, my last upload might not have (this could be the error you are getting)

regards

Stu
 

Attachments

  • SMB Explorer Example.zip
    349.7 KB · Views: 1,129
Last edited:
Upvote 0
Top