Android Question Music player chooser

ipika july

Member
Licensed User
Longtime User
I want to allow user to pick a media player to play my file
here is java snippet

B4X:
Intent viewIntent = new Intent(Intent.ACTION_VIEW);
File file = new File((String) ((TextView) item).getText());
viewIntent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(Intent.createChooser(viewIntent, null));

How to use this ?
currently i am using

B4X:
  Dim r As Reflector
   Dim f As Object
   f = r.CreateObject2("java.io.File", Array As Object("/sdcard/test.amr"), Array As String("java.lang.String"))
   Dim share As Intent
   share.Initialize(share.ACTION_VIEW,r.RunStaticMethod("android.net.Uri", "fromFile", _
      Array As Object(f), Array As String("java.io.File")))
    share.WrapAsIntentChooser("Choose")
   StartActivity(share)

But this code doesnot opens a popup to choose.And i cannot find setDataAndType method in intent lib.
 

ipika july

Member
Licensed User
Longtime User
No. I actually want to give option to user to choose audio player he want to use to play music from my app.
Just like photoviewer to view photos.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…