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):
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
THIS is an old post, so perhaps isn't already relevant, but the last comment in the last answer is interesting.

Try installing THIS
 
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…