Start Google Now on Music Recognition - android

Is there a way to automatically start Google Now on Music Recognition? I'd need it to create a DashClock extension that start Music Recognizing...
As far as I speak, I can start package com.google.android.googlequicksearchbox successfully but I cannot start voice input... I would not use startActivity for result since I would not need a result, I would really just start Google Now voice recognition feature, is there a way to do it programmatically?

Otherwise, to simply launch Google Now Song Recognition service (without having to tap on "Listen to Music", to be clear), you can create an Intent with the string
"com.google.android.googlequicksearchbox.MUSIC_SEARCH";
that would launch directly the proper interface.

I just found a way to achieve my goal:
Intent intent = new Intent();
intent.setClassName("com.google.android.googlequicksearchbox","com.google.android.googlequicksearchbox.VoiceSearchActivity");
starting this intent will bring up voice search window.

Related

MediaStore.Audio.Media.RECORD_SOUND_ACTION not working in nougat

I am using MediaStore.Audio.Media.RECORD_SOUND_ACTION to open sound recorder application, I am not able to open application as no default application present, then i install two voice recorder application even though not able to see these application in my chooser intent. I am using following code-
Intent soundRecorderIntent = new Intent(); // create intent
soundRecorderIntent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION); // set action
startActivityForResult(soundRecorderIntent, ACTIVITY_RECORD_SOUND); // start activity
It works well in marshmallow
The code is correct and you've probably found an app that supports the intent by now. But to prevent that others waste their time like I did, here's a quick note:
Most of the currently top rated voice recording apps in the Play Store do not provide the necessary intent filter.
That seemed so unrealistic to me that I doubted my code when it didn't work after having installed the five most popular voice recording apps. But there's a handy manifest viewer app that reveals that their manifests simply do not declare the intent filter. So, as said, the code is correct.
To save you the time from searching for a suitable app, here are two that are invocable:
Audio Recorder from Sony
Samsung Voice Recorder from Samsung
There is no requirement for a voice recorder app to support this Intent action, and apparently your device does not ship with an app that supports this Intent action either. Your code itself seems fine.
If recording is optional to your app, catch the ActivityNotFoundException and tell the user that they do not have a recorder, and perhaps suggest to them that they install one that you test that works, if you can find one.
Otherwise, record the audio yourself, using MediaRecorder.

Intent to simulate google now voice command with query

I am trying to use the googlequicksearchbox to do some actions directly, without the click button confirmation...
for example:
When I click at the mic of Google Now and say "Me acorde às 9:00" (Wake-up me at 9)... Google now makes an alarm for 9 without needing confirmation. Like this:
But if I use this intent:
String query = "Me acorde às 9:00";
final Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.setPackage("com.google.android.googlequicksearchbox");
intent.putExtra(SearchManager.QUERY, query);
startActivity(intent);
to start googlequicksearchbox with the same text that was recognized, Google Now makes the alarm, but now requires confirmation click at the blue button (reminders, etc, also requires). Like that Screenshot >> Screenshot alarm require confirmation
Someone knows some way of make the intent start google search with a query and not requires the click confirmation? like "simulate a google now voice command"??
P.S1.: I am using my own voice recognition inside of my app for other purposes, and I am trying to make the Google Now interpret the voice for just some commands... So, unfortunately, I can't execute the google now voice recog...
P.S2.: I don't know how to interpret the voice (get the hour, minutes, etc.) and make the alarm by the direct intent... then, use the google now to interpret is the best option for me.

Voice recognition - with templates (android wear)

I am trying to develop an application for Android wear that on a button click will ask the user to speak something and send it to a webserver. I also need to have a list of pre-defined templates, similar to what Hangouts works.
What I have tried:
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Send to server");
startActivityForResult(intent, SPEECH_REQUEST_CODE);
This works, but I cannot supply the user a set of pre-defined templates.
Reading this - https://developer.android.com/training/wearables/notifications/voice-input.html I see that it is possible to do this in a notification... but this will not be in the front, I need this UI to be modal/blocking, so a notification is not good for my use case.
What are my options? How can I implement this?
Unfortunately, other than Receiving Voice Input in a Notification there is no way to use voice recognition with pre-defined text responses.
Based on the documentation : Adding Voice Capabilities
Voice actions are an important part of the wearable experience. They let users carry out actions hands-free and quickly. Wear provides two types of voice actions:
System-provided
These voice actions are task-based and are built into the Wear platform. You filter for them in the activity that you want to start when the voice action is spoken. Examples include "Take a note" or "Set an alarm".
App-provided
These voice actions are app-based, and you declare them just like a launcher icon. Users say "Start " to use these voice actions and an activity that you specify starts.
Also as discussed in 24543484 and 22630600, both implemented a notification in their android to get the voice input.
Hope this helps.

Launch Google Now or phone default voice search?

I need to give users a method to launch their phone's voice assistant from my app, be it Google Now or anything else.
When searching on how to do this I keep finding explanations on how to get voice input while I just want to launch Google Now in "listening" mode. This question clearly asks for the same thing but the accepted answer explains how to open voice input:
How to programmatically initiate a Google Now voice search?
I know this can't be a rare case, how can it be done?
startActivity(new Intent(Intent.ACTION_VOICE_COMMAND).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
worked for me and seems more intuitive.
It is not very clear what exactly you are trying to achieve, but I hope following will be helpful.
The code given at How to programmatically initiate a Google Now voice search? will launch the default speech recognizer (or "voice assistant" as you have put it).
Following, however, will explicitly open (if available) Google's speech recognizer:
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");
}

Android: Launch music player service from application

I know that it is possible to launch the music player using an intent using either of the follow:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
or
Intent intent = new Intent(MediaStore.CATEGORY_APP_MUSIC);
startActivity(intent);
However is it possible to start the default music player as a SERVICE rather than an activity? Moreover, is it possible to send actions to that service once it has been created?
However is it possible to start the default music player as a SERVICE rather than an activity?
No, in part because there is no requirement for the user's chosen music player to even have a service. Moreover, the ACTION_VIEW Intent action is only generally supported by activities.
Moreover, is it possible to send actions to that service once it has been created?
Not generally.
There thousands of "music player" apps for Android, any of which can be the "default" for a given user and device. You are welcome to ask each and every one of them if they offer some sort of command-based interaction with some sort of music-playing Service to allow third-party apps to control their player. Some might. Most won't.

Categories

Resources