Android Question help with intent

moster67

Expert
Licensed User
Longtime User
Now, I have rarely used intents and I wonder if anyone could help me to get the following java-snippet working in B4A:

B4X:
'Intent intent = new Intent(Intent.ACTION_MAIN);
'intent.setClassName("com.google.android.googlequicksearchbox",
'        "com.google.android.googlequicksearchbox.VoiceSearchActivity");
'Try {
'    StartActivity(intent);
'} Catch (ActivityNotFoundException anfe) {
'    Log.d(TAG, "Google Voice Search is not found");
'}

And what would I need to put in the manifest?

The idea is that the app detects a phone-number (this already works), and if the phone-number is a match, I simply want to get the google search open up. I would like to avoid having an activity in this app.
 

moster67

Expert
Licensed User
Longtime User
I get this error with your code (just running it in Main):
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
test
Error occurred on line: 49 (Main)
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.googlequicksearchbox/com.google.android.googlequicksearchbox.VoiceSearchActivity}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1820)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1531)
at android.app.Activity.startActivityForResult(Activity.java:4403)
at android.app.Activity.startActivityForResult(Activity.java:4362)
at android.app.Activity.startActivity(Activity.java:4686)
at android.app.Activity.startActivity(Activity.java:4654)
at anywheresoftware.b4a.keywords.Common.StartActivity(Common.java:839)
at b4a.example.main._openvoice(main.java:415)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
** Activity (main) Resume **
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Thank you for your help. I got it working like this:

B4X:
Dim in As Intent
    in.Initialize(in.ACTION_MAIN, "")
    in=pac.GetApplicationIntent("com.google.android.googlequicksearchbox")
    StartActivity(in)

'pac = PackageManager from Phone-library

This works both with (the deprecated) Google Now and the new Google Assistant.
 
Upvote 0
Top