Android Question [SOLVED] launch youtube search with my string

Traiser

Member
Licensed User
Longtime User
hi all, i have one problem with launch youtube search with my string from my app,

i try use this code but don't work:
B4X:
Dim Intent1 As Intent

Intent1.Initialize(Intent1.ACTION_VIEW, "")
Intent1.SetComponent("com.google.android.youtube/.ResultsActivity")
Intent1.PutExtra("query", test)

StartActivity(Intent1)


in the internet i found this java code:
B4X:
 Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra("query", "Android");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

can you help me? thanks!
 

Traiser

Member
Licensed User
Longtime User
ok thanks work if i use
B4X:
Intent1.SetComponent("com.google.android.youtube")
but show popup "complete action with"

how can I remove this popup?
if i use
B4X:
Intent1.SetComponent("com.google.android.youtube/.ResultsActivity")
don't work :-(
 
Upvote 0

Traiser

Member
Licensed User
Longtime User
i resolve with this code:

B4X:
Sub SetPackage(i As Intent, PackageName As String)
    'couldn't find SetPackage-method among B4A's default intents. We therefore use Agraham's reflection-library to add it.
  Dim rf As Reflector
  rf.Target = i
  rf.RunMethod2("setPackage", PackageName, "java.lang.String")
End Sub

and

B4X:
            dim intent1 as intent
            Intent1.Initialize("android.intent.action.SEARCH", "")
            SetPackage(Intent1, "com.google.android.youtube")
            Intent1.PutExtra("query", test)
            StartActivity(Intent1)

Thanks!
 
Upvote 0
Top