How can I use RecognizerIntent to force using Turkish? - java

to voice recognation:
I use this code to detect:
Intent myintent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
myintent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
myintent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, lcl );
the lcl is a variable. I choice turkish it works on turkish but at the same time works with english
I do not understand If google understand every language why we use EXTRA_LANGUAGE parameter.
I want to google force to detect turkish
is it possible

try this:
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "tr-TR");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getPackageName());
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

Related

“Protected Apps” setting on Android phones

We can ask the user to protect our app, by using (e.g. Huawei phones):
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
startActivity(intent);
Is there a way of knowing if the app got protected or not? I'm trying to avoid asking the user to protect the app e.g. every time the app is created.
For other intents, I can use:
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(
new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + getPackageName()))
,
PackageManager.MATCH_DEFAULT_ONLY);
System.out.println("MY_intent_TEST_1(looks always true): "+( list.size() > 0 ) );
PowerManager pwm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
System.out.println("MY_intent_TEST_2(true when whitelisted): "+ pwm.isIgnoringBatteryOptimizations(context.getPackageName()) );
P.S. I'm learning from: "Protected Apps" setting on Huawei phones, and how to handle it
Because related interfaces are not exposed, currently you cannot get to know whether the app got protected or not.

can any one help me on this android app

hello i have an app of POS ( point of sale )
i wanted to make it send printing data to be printed through bluetooth printer
i found this solution
https://play.google.com/store/apps/details?id=com.fidelier.posprinterdriver
its a driver for my printer
they say
+### Print from your Android App (interactive user action)
+
+Create your ESC data using the helpers Create an Android Intent using Add your ESC data as a “Data” extra Start the intent.
+You can be printing in minutes with just a couple lines of code. It's as simple as creating your intent, adding your ESC formatted string and start the (service) intent.
+
+Example:
+
+```java
+
+String dataToPrint="$big$This is a printer test$intro$posprinterdriver.com$intro$$intro$$cut$$intro$";
+
+Intent intentPrint = new Intent();
+
+intentPrint.setAction(Intent.ACTION_SEND);
+intentPrint.putExtra(Intent.EXTRA_TEXT, dataToPrint);
+intentPrint.setType("text/plain");
+
+this.startActivity(intentPrint);
+
+```
can any body tell me how can i do that ???
where should i put these codes ? ?
Lets say you have your activity with a button link to this method :
public void click(View v){
Intent intentPrint = new Intent();
intentPrint.setAction(Intent.ACTION_SEND);
intentPrint.putExtra(Intent.EXTRA_TEXT, "Just some dummy text to print");
intentPrint.setType("text/plain");
this.startActivity(intentPrint);
}
By clicking on this button, the intent will be launched, this will probably open a list of application that can handle this kind of intent (ACTION_SEND), choose the correct one and this should do it.

how to get all music players

I want to query all activitys that can play a music file.
I have tried to get all music players like this:
Intent resolve_intent = new Intent();
resolve_intent.setAction(android.content.Intent.ACTION_VIEW);
resolve_intent.setType("audio/*");
packages = getPackageManager().queryIntentActivities(resolve_intent, 0);
if (packages == null || packages.size() <= 0)
{
//none found
}
but i everytime get an empty (or null) list...
if i do this for type = "image/* or "video/*"
i get all applications that can handle this type.
only for "audio/*" i get no players installed, even if i know that there is one...
so what am i doing wrong?
Fond it myself:
i forgot to set the Data, and i didn't know android uses the data too
to resolve the matching intents...
working code:
Intent resolve_intent = new Intent();
resolve_intent.setAction(android.content.Intent.ACTION_VIEW);
resolve_intent.setDataAndType(Uri.fromFile(new File("/some/path/to/a/file")), "audio/*");
List<ResolveInfo> packages = context.getPackageManager().queryIntentActivities(resolve_intent, 0);

Notification sound goes infinity and never stop

I made a notification with sound and when it notify make sound but never stop. Is there any way to limit the notification's sound time?
this is my notification code
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context).setSmallIcon(R.drawable.icon)
.setContentTitle(title).setContentText(detail);
mBuilder.setDefaults(Notification.DEFAULT_VIBRATE);
mBuilder.setDefaults(Notification.DEFAULT_LIGHTS);
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(context);
String sound = pref.getString("ringtonePref", "default");
Uri uri = Uri.parse(sound);
mBuilder.setSound(uri,RingtoneManager.TYPE_ALARM);
Had the same problem. I used NotificationBuilder to build everything. Called build() to get the noti object and I did the following:
notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
I believe you need to change TYPE_ALARM to TYPE_NOTIFICATION.
Some of the ringtones contain ANDROID_LOOP metadata to make the music loop.
These sounds will loop forever. So it is better to use sounds specific for default notifications or sounds that doesn't have ANDROID_LOOP metadata.

How to open Google Maps using address?

How can I open Google Maps(using Intents or adding Google Maps into my application) with address? I have the address, but I don't have latitude/longitude. How can I do it? Thank you.
use below code,
String map = "http://maps.google.co.in/maps?q=" + str_location;
// where str_location is the address string
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(map));
startActivity(i);
From my personal Code Library. ;)
public static Intent viewOnMap(String address) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("geo:0,0?q=%s",
URLEncoder.encode(address))));
}
public static Intent viewOnMap(String lat, String lng) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("geo:%s,%s", lat, lng)));
}
String geoUri = "http://maps.google.com/maps?q=loc:" + addressName;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoUri));
context.startActivity(intent);
Change the bold part of this URL to your company address. It's best if you replace all spaces with a plus (+) character, but should work with spaces too:
http://maps.google.com/maps/geo?q=620+8th+Avenue,+New+York,+NY+10018,+USA&output=csv&oe=utf8&sensor=false
Raise a request to above URL. For more information refer http://androidadvice.blogspot.in/2010/09/asynchronous-web-request.html
This will generate a code that looks something like this:
200,8,40.7562008,-73.9903784
The first number, 200, says that the address is good. The second number, 8, indicates how accurate the address is. The last two numbers, 40.7562008 and -73.9903784, are the latitude and longitude of this address. Use these to get your google map working.
Note : The above steps have been copied from http://webdesign.about.com/od/javascript/ss/add-google-maps-to-a-web-page_2.htm
You can use Google Geocoding API, which converts your physical address into latitude and longitude. API returns it into XML or JSON format. You just need to parse the data to get latitude and longitude. After receiving latitude and longitude you can load it on mapview.
Geocoding api link :
https://developers.google.com/maps/documentation/geocoding/
Hope this helps.
As of 2017 the recommended by Google approach is using the Google Maps URLs API that provides universal cross-platform URLs. You can use these URLs in your intents.
Example of such URL from the documentation:
https://www.google.com/maps/search/?api=1&query=centurylink+field
Hope this helps!
Little late to the party. I prefer #st0le's answer but URLEncoder.encode(String s) is deprecated as of API 16. You need to pass a second argument as well. Check the answer below.
public static Intent viewOnMapA(String address) {
try {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("geo:0,0?q=%s",
URLEncoder.encode(address, "UTF-8"))));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
From the current documentation
https://developers.google.com/maps/documentation/urls/get-started
It is better to use
https://www.google.com/maps/dir/?api=1&query=address
so:
val address = "some address"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com/maps/dir/?api=1&query=$address"))
startActivity(intent)

Categories

Resources