onStartListening when is it called? - java

I'm working on an android application which is basically a service to convert speech in to text as a background process, I'm getting help from How to register a custom speech recognition service? but I'm unable to know when onStartListening() is called.
Signature:
protected void onStartListening(Intent recognizerIntent, Callback listener)
Can any one can help or help me add more statements in the code given in that link so that I can recognize the speech in to text and show it in the toast?

In general, there are 2 kinds of apps:
apps that direct the user to convert audio into text, but don't actually implement the speech recognition part but just do the UI part (microphone button, VU visualizer) (let us call them app1);
apps that actually convert audio into text, either on the device or by calling a cloud service, and to make themselves available to app1, they extend RecognitionService (let us call them app2).
Since you mention "toast" (i.e. a UI element), I guess you want to implement app1?
app1 needs to do the following:
Intent intent = ...
SpeechRecognizer recognizer = ...
recognizer.setRecognitionListener(new RecognitionListener() { ... });
recognizer.startListening(intent)
Based on the specified intent and taking into account the user settings, Android finds a suitable app2 to service app1.
app2 extends the abstract class RecognitionService, i.e. it needs to implement a bunch of methods, among them onStartListening. The latter is called by Android when app1 calls startListening.
As the author of app1 you just need to provide the input details to the recognizer using the various intent extras, provide the handling of the output of the recognizer using the methods of the interface RecognitionListener, and start the app2 using startListening.

Related

How to trigger KeygaurdManager to take fingerprint programmatically

As soon as I receive a push notification from my app I want to trigger the KeyguardManager to launch the fingerprint/pass code screen to open the phone from lock screen so that person can enter the phone and unlock the device.
I want to trigger this programmatically similar to when we click on any notification from lock screen we get the fingerprint/pass-code screen.
I did a lot of RnD but didn't find any solution, this is one of the challenging use case task given to me in class, I have been exploring a lot from quite few weeks with no success at all.
Did tried Broadcast receiver with BiometricManager and many things with no success, any lead will be very helpful.
As soon as you receive push message, onNotificationReceived() (or some other method if you use some 3rd party libs) method gets called as below. from there, you can launch your Main screen where you have written biometric/unlocking code.
class MyReceiver : PushReceiver {
override fun onNotificationReceived(message: Message) : Boolean {
//Launch your MainActivity where you can show Unlock screen.
return super.onNotificationReceived(message);
}
}

Application "blinks" when speechRecognition is restarted

I'm developing an application that among other things , lets user interact with it by voice recognition (Speech to Text).For example user speaks the word "contacts" and the application can recognize and proceed to use logic to it to do something (i.e get the list of contacts and present them).
Now I have used a custom speech Recognizer , and not the one Google provides with the alert dialog.
I also have an animated gradient as a background with some colors.
From the RecognitionListener we get either an error as a response or we get results from the method onResults(Bundle results).In both cases after the response i need to restart the listener in order for the user to continue to interact with the application. However, when my speechRecognition is destroyed and created again, my application "blinks"(very quick black screen, but then the Ui is returned to normal).
I know that the problem is happening because i try to destroy my speechListener and then i re-create it(By calling the function restartSpeechListener), but i cannot seem to find a way to solve this "blinking".
Below is my code for the speechRecognizer initiation and restart :
public void startRecognising() {
mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(this);
mySpeechRecogniser listener = new mySpeechRecogniser();
Intent mSpeechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE,
"el");
mSpeechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
mSpeechRecognizer.setRecognitionListener(listener);
mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
startActivity(mSpeechRecognizerIntent);
}
// Restart speech recogniser
public void restartSpeechListener() {
mSpeechRecognizer.stopListening();
mSpeechRecognizer.destroy();
startRecognising();
}
Any suggestions or help would be very helpful !

How to hide Calling UI and make calls with custom UI?

I have created a custom ui and making a call using telecom manager for direct dialing. But every time Device default Calling UI is opening.
Here is some code for making calls directly...
TelecomManager telecomManager=(TelecomManager)getSystemService(Context.TELECOM_SERVICE);
Uri uri = Uri.fromParts("tel", phonenumber, null);
Bundle extras = new Bundle();
extras.putBoolean(TelecomManager.METADATA_IN_CALL_SERVICE_UI, true);
extras.putBoolean(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE,true);
try {
if (telecomManager!=null) {
telecomManager.showInCallScreen(true);
}
}catch(SecurityException incoming){
incoming.printStackTrace();
}
try {
if (telecomManager!=null) {
telecomManager.placeCall(uri, extras);
}
}catch(SecurityException unlikely){
unlikely.printStackTrace();
}
is there a way to hide the default calling ui and use our own calling ui.?
Any help will be appreciated.
See the API docs on how to use the placeCall API. METADATA_IN_CALL_SERVICE_UI should not be passed to placeCall, and EXTRA_PHONE_ACCOUNT_HANDLE is not a boolean extra. You need to pass in a PhoneAccountHandle. However, if you're just trying to place a regular mobile call, just omit that extra as the system will pick the right one.
showInCallScreen should also only really be used by the Dialer app to bring its UI to the foreground; its not going to have any impact in your case.
If you want to use your Dialer app as the in-call UI, you need to change it in the system settings.
System Settings --> Apps & Notifications --> Advanced --> Default Apps --> Phone App. Choose your app there.
To be a default phone app you need to handle the DIAL intent and implement the InCallService API.

Is it possible to send a MediaPlayer object from service to a fragment?

In my android app I want to implement a visualizer graph linked to a Media Player following this idea. I use a service to manage my background streaming with MediaPlayer. The problem comes with the transmission of my MediaPlayer object to my fragment. I need to have it there because is where the link occurs:
// We need to link the visualizer view to the media player so that
// it displays something
mVisualizerView = (VisualizerView) findViewById(R.id.visualizerView);
mVisualizerView.link(mPlayer);
In summary, I need to send MediaPlayer object from my service to my fragment. Any idea?

Android SMS API

I know that the SMS content provider is not part of the public API (at least not documented), but if I understand correctly it's still possible to use many of the SMS features as long as you know how to use the API(?).
E.g it's pretty straightforward to insert an SMS into your inbox:
ContentValues values = new ContentValues();
values.put("address", "+457014921911");
contentResolver.insert(Uri.parse("content://sms"), values);
Unfortunately this does not trigger the standard "new-SMS-in-your-inbox" notification. Is it possible to trigger this manually?
Edit: AFAIK the "standard mail application (Messaging)" in Android is listening for incoming SMSes using the android.permission.RECEIVE_SMS permission. And then, when a new SMS has arrived, a status bar notification is inserted with a "special" notification id.
So one solution to my problem (stated above) could be to find, and send the correct broadcast intent; something like "NEW SMS HAS ARRIVED"-intent.
Edit: Downloaded a third party messaging application (chompsms) from Android market. This application satisfies my needs better. When i execute the code above the chompsms notice the new sms and shows the "standard status bar notification". So I would say that the standard Android Messaging application is not detecting sms properly? Or am I wrong?
Unfortunately the code responsible for these notifications is hidden in the messaging application. The class MessagingNotification has a static method updateAllNotifications that you could call using a PathClassLoader and reflection:
PathClassLoader c = new PathClassLoader("/system/app/Mms.apk", getClassLoader());
Class.forName("com.android.mms.util.ContactInfoCache", true, c)
.getMethod("init", Context.class).invoke(null, context);
Class.forName("com.android.mms.transaction.MessagingNotification", true, c)
.getMethod("updateAllNotifications", Context.class).invoke(null, context);
This is obviously a very bad idea for several reasons but I can't think of another way to do what you described.
Could you trigger a PUSH notification after the SMS?
Thread: Does Android support near real time push notification?
Maybe you should replace
content://sms
with
content://sms/inbox

Categories

Resources