Google glass voice recognition - java

I want to do a google glass application that can recognize the words said by others to you.
I tries to use the same Android code for voice recognition
#Override
public void onClick(View v) {
Intent i = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(i, REQUEST_OK);
} catch (Exception e) {
Toast.makeText(this, "Error initializing speech to text engine.", Toast.LENGTH_LONG).show();
}
}
This didn't work because, this code recognizes only the speech the person putting the glass on his head is saying.
I need my application to also recognize the voice of others talks to me.
Anyone could help please?
Thanks

If the other person is close enough of the microphone, it should work.
The problem here is about the hardware not the code, the microphone is only receiving the voice of the person around it, if you are too far it won't work.

Related

Alternative for toast when using widgets in Android 12 as toasts are now truncated

hope someone can point me in the right direction.
I have created an app with a widget. The widget is a simple button that runs a bit of code and then returns a message to the user via a toast. However, I realise in Android 12 toasts are now truncated to two lines and often the message is longer. I'm not keen on snackbars but appreciate my main app can be converted to use them but what should I use to do the same job via a widget?
Snackbars require a layout view to work but I can't figure out how to retirve it from teh widget code. I could use an alertdialogue but although the code compiles they simple don't seem to show up. I'm open to suggestions here...
What is the best way of popping up a message on the homescreen when a widget is pressed? Is there any way of telling the app not to truncate toasts or if not what's the best alternative?
Many thanks
Nat
Finally worked out how to do this myself... Its kinda obvious when you know but isn't that always the way?
Create a new activity. You can make it look like a dialog by using this theme in your manifest - android:theme="#style/Theme.AppCompat.Dialog". Then from your widget simply call showmessage as outlined below...
public void showamessage (String thetitle, String themessage) {
PendingIntent pendingIntent;
Intent intent = new Intent();
intent.setClass(thecontext,MessageActivity.class);
intent.putExtra("TheTitle",thetitle);
intent.putExtra("TheMessage",themessage);
pendingIntent = PendingIntent.getActivity(thecontext, 0, intent, FLAG_IMMUTABLE);
try {
pendingIntent.send(thecontext, 0, intent);
} catch (PendingIntent.CanceledException e) {
System.out.println( "Sending pendingintent failed: " );
}
}

How to create an Intent that gives you suggestion every time you click

I am developing an app, where I am using a Share Button whenever the user clicks on the share button the suggestion window will be opened like Messenger, WhatsApp, Bluetooth, etc.
But when I chose from suggestions, and the next time I click on share button it doesn't provide any suggestion but take me to the app which I chose last time from suggestion I cleared app Cache and App data also but doesn't work, direct me to the app that I chose from suggestion last time.
Share Button Code:
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, UserStatusforshare);
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
whatsappIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
try {
context.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context, "Whatsapp have not been installed.", Toast.LENGTH_SHORT).show();
}
Alternate Code I have:
Uri imgUri = Uri.parse(postImage);
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, postDescription);
whatsappIntent.putExtra(Intent.EXTRA_STREAM, imgUri);
whatsappIntent.setType("image/jpeg");
whatsappIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
whatsappIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
try {
context.startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context, "No supported app exists!", Toast.LENGTH_SHORT).show();
}
Here in this code, there is one thing image here I am sharing an Image also... But that one work the same way doesn't provide suggestions every time click, direct me to the app I chose from the last only suggestions.
I've tried some answer from StackOverflow, but I am unable to understand and my search is also not very good... Please Help I am new to android, Thanks in Adnvance
Please try to start intent with this code :
startActivity(Intent.createChooser(whatsappIntent, "The title what you want to show"));

Android wear: calling a "default fitness app" from java

I'm trying to have a function in my App for Android Wear to call the "default Fitness App"...
I already see in a WatchFace that it is possible tapping on an element to call the App to display a statistic of heart rate or steps count or similar.
If I change the App (for example from Google Fit to Moto Body), and I tap again on the element the new App will be started.
So it must be possible to call an action (Intent?) with some value and Android call the properly App.
I searched this "some value" but I didn't found anything. I'm sure, it exists...
Can someone help me?
Thanks a lot
Luca
After many trials and debugging other Apps, I found a solution...
I post it here in the case someone other needs it:
Intent intent = new Intent(Fitness.ACTION_VIEW, null);
intent.setType("vnd.google.fitness.data_type/com.google.heart_rate.bpm");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try
{
startActivity(intent);
}
catch(ActivityNotFoundException e)
{
Log.v(PROGRAM, "Unable to start Fitness App\n" + e.toString());
}
Regards
Luca

My QR reader app won't open Links

I made a QR reader APP for my school project, the app works very well but it has a little mistake. When I scan a QR code the app just shows me the text. However, when I created a QR code linked to "www.google.com" (a simple link), my app just shows me "www.google.com" and doesn't open it in the browser.
I use this video to make my app : https://youtu.be/Fe7F4Jx7rwo
He is a nice guy He said : "use intent to open it in a browser"
But as I said in previous posts : "in my school my teacher prefer to teach Visual Basic instead Java or C++" ... So I'm a 0 in Java or C++
Can anyone suggest what to do?
I suggest the following. When you get the text from the QR call the following code to either open the browser or show the text on the screen (your current implementation):
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...
String text = resultCode.getContents();
if (Patterns.WEB_URL.matcher(text).matches()) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(text));
startActivity(browserIntent);
} else {
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
}
}

Android: How to launch call intent using google voice?

How to launch specific intent (such as call) using google voice? How to pass phone number using intent? Following code launches google voice but what value to be passed for making call using google voice as intent extras?
final Intent intent = new Intent();
intent.setComponent(new ComponentName("com.google.android.apps.googlevoice", "com.google.android.apps.googlevoice.activity.conversationlist.ConversationListActivity"));
intent.putExtra("label", "<phone number>");
startActivity(intent);
Here what should i put in label to start the intent that launches a call using google voice?
Any help is appreciated... Thanks in Advance...
NEVER target applications directly like that UNLESS it is in your package. You should be using the Intent filter to catch that particular application. Sometimes you have to target an application like this, but this brings up the risk of change in package name errors.
To handle your particular application, you need to look at how information is being passed into Google voice. this will give you insight and how to target it WITHOUT targeting the exact package name.
What #JoxTraex said makes sense. However some clients need funny features like this, so we have no way but to implement this:
try {
Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + mobile));
intent.setPackage("com.google.android.apps.googlevoice");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (ActivityNotFoundException anfe) {
GMHintManager.getInstance().showError(context, "Google Voice not installed");
}
Yes, you should try-catch ActivityNotFoundException.

Categories

Resources