I tried Google barcode-reader from https://github.com/googlesamples/android-vision
This example doesn't work. When I tab to screen it always detect
"no barcode detected"
Debug reason :
private boolean onTap(float rawX, float rawY) {
//TODO: use the tap position to select the barcode.
BarcodeGraphic graphic = mGraphicOverlay.getFirstGraphic();
Barcode barcode = null;
if (graphic != null) {
barcode = graphic.getBarcode();
if (barcode != null) {
Intent data = new Intent();
data.putExtra(BarcodeObject, barcode);
setResult(CommonStatusCodes.SUCCESS, data);
finish();
}
else {
Log.d(TAG, "barcode data is null");
}
}
else {
Log.d(TAG,"no barcode detected");
}
return barcode != null;
}
graphic variable is always Null
See the image:
Anyone faced this problem? Can you let me know how to resolve it?
Thank you so much!
So I guest you are new to Android Mobile Vision, in the new version of Google Play services (v9) they temporarily disabled the feature due to a serious bug in that feature, you can check the release note here:
https://developers.google.com/android/guides/releases#may_2016_-_v90
As #Vietnt134 have already answered, Android Mobile Vision is temporarily disabled.
You can follow this topic to know if something knew came up:
https://github.com/googlesamples/android-vision/issues/98
People are pretty mad with Google about this. I hope they solve this quickly.
getFirstGraphic returns null whenever no graphics have been added to the overlay; in the barcode example, this is when no barcodes have been detected in the frame.
Check if barcodeDetector.isOperational() is returning false in BarcodeCaptureActivity.java. If it's returning false, has for several minutes, and you aren't in a low storage condition, there's a very good chance this is because of a current service outage.
More details can be found here: https://github.com/googlesamples/android-vision/issues/98 We'll update that issue as soon as we have a resolution.
Related
What a tricky question, you will probably want more information..
I'm currently building an app that use the camera in background. This is ethic, and the user has been warned, so don't worry.
I'm using CameraSource from com.google.android.gms.vision.
So the user is free to launch other app and do anything he want to do. Even start other app which access the camera ! Here problems come..
I'm using Flutter as framework.
When user open an other app that use the camera, my app lost signal and Flutter trace only print :
E/Camera ( 3154): Error 2
Nothing else.. No Exceptions, No traces, Nothing to know here it come from, why or how to handle it !
If you have any idea how to restart the camera untill it's available again, it could save me days.
You should call cameraController.dispose() when your the app stops (goes to the background or other application opens in top of the app).
Here is the example from the official camera documentation on how they handle app lifecycle for the camera.
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
// App state changed before we got the chance to initialize.
if (controller == null || !controller.value.isInitialized) {
return;
}
if (state == AppLifecycleState.inactive) {
controller?.dispose();
} else if (state == AppLifecycleState.resumed) {
if (controller != null) {
onNewCameraSelected(controller.description); // Here we reinitialize the cameraController
}
}
}
Here is the link to camera documentation.
I'm using Android's TextToSpeech class. Everything is working normally. However, there are languages/locales that aren't installed by default but supported by the TTS engine and I can't capture the state of missing voice data.
With the internet on, when I try to setLanguage to a new locale which its voice data hasn't been downloaded, it'll simply download the voice data and perform the speak method normally/successfully.
However, with internet off, when I try to setLanguage to a new locale which its voice data hasn't been downloaded, it attempts to download the voice data. But with no internet, it just indicates "downloading" on the "TTS voice data" settings screen under "Language and input" for the selected locale, without any progress. And as expected the speak method doesn't work since the voice data isn't downloaded. When this happens, I would think TTS methods setLanguage/isLanguageAvailable will return LANG_MISSING_DATA for me to capture this state, however, it simply returns LANG_COUNTRY_AVAILABLE. The situation is shown in this image:
I want to be able to detect when the voice data of the locale being chosen isn't downloaded/missing and either give a toast message or direct user to download it. I have seen several posts suggesting the use of using isLanguageAvailable like this one. I also looked at the android documentation and it seems like isLanguageAvailable's return values should capture the state of missing voice data with LANG_MISSING_DATA.
I also tried sending an intent with ACTION_CHECK_TTS_DATA as the other way to check for missing data as suggested in the Android documentation I linked. However, the resultCode again didn't capture/indicate that the voice data is missing (CHECK_VOICE_DATA_FAIL) but returned CHECK_VOICE_DATA_PASS instead.
In this case, how should I capture the state of a language/locale being available/supported, with the voice data missing? I'm also curious why CHECK_VOICE_DATA_PASS and LANG_MISSING_DATA aren't the values returned. When the voice data is missing, shouldn't it return these values? Thanks!
Below is the return value when I try to use setLanguage and isLanguageAvailable on locales that haven't had its voice data downloaded (0 and 1 are the returned value of the method shown in the logs, -1 is the one that corresponds to missing voice data):
You can find all available Locale of the device using following function. hope this code will help you.
Locale loc = new Locale("en");
Locale[] availableLocales= loc.getAvailableLocales();
Boolean available=Boolean.FALSE;
for (int i=0;i<availableLocales.length;i++)
{
if(availableLocales[i].getDisplayLanguage().equals("your_locale_language"))
{
available=Boolean.TRUE;
// TODO:
}
}
I have this implementation as part of a wrapper class to work with TextToSpeech, I hope it helps:
public boolean isLanguageAvailable(Locale language)
{
if(language == null) return false;
boolean available = false;
switch (tts.isLanguageAvailable(language))
{
case TextToSpeech.LANG_AVAILABLE:
case TextToSpeech.LANG_COUNTRY_AVAILABLE:
case TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE:
if(Build.VERSION.SDK_INT >= 21){
tts.setLanguage(language);
Voice voice = tts.getVoice();
if(voice != null){
Set<String> features = voice.getFeatures();
if (features != null && !features.contains(TextToSpeech.Engine.KEY_FEATURE_NOT_INSTALLED))
available = true;
} else available = false;
tts.setLanguage(this.language);
}
break;
case TextToSpeech.LANG_MISSING_DATA:
case TextToSpeech.LANG_NOT_SUPPORTED:
default:
break;
}
return available;
}
It looks like a long waiting question but anyway. It seems that you have to check voice features to find it out:
Set<String> features = voice.getFeatures();
if (features.contains(TextToSpeech.Engine.KEY_FEATURE_NOT_INSTALLED)) {
//Voice data needs to be downloaded
...
}
I have an application that according to some events, changes a normal notification to text-to-speech in order to since sometimes the phone isn't available to users, and it'll be safer not to handle the phone.
For example, when you're driving, this is dangerous, so i want to turn the notifications to text-to-speech.
I've looked for a long time some explanation for turning text-to-speech when driving, but i can't find any reference for that no where i search.
For generating text-to-speech, i have this part, which works fine :
private TextToSpeech mTextToSpeech;
public void sayText(Context context, final String message) {
mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
try {
if (mTextToSpeech != null && status == TextToSpeech.SUCCESS) {
mTextToSpeech.setLanguage(Locale.US);
mTextToSpeech.speak(message, TextToSpeech.QUEUE_ADD, null);
}
} catch (Exception ex) {
System.out.print("Error handling TextToSpeech GCM notification " + ex.getMessage());
}
}
});
}
But, i don't know how to check if i'm currently driving or not.
As Ashwin suggested, you can use Activity recognition Api, but there's a downside of that, the driving samples you'll receive, has a field of 'confidence' which isn't always accurate, so you'll have to do extra work(such as check locations to see if you actually moved) in order to fully know if the user moved.
You can use google's FenceApi which allows you to define a fence of actions such as driving, walking, running, etc. This api launched recently. If you want a sample for using it, you can use this answer.
You can pull this git project (everything free), which does exactly what you want : adds to the normal notification a text-to-speech when you're driving.
In order to know whether you are driving or not you can use Activity Recognition API
Here is a great tutorial that might help you out Tutorial and Source Code
I want to directly launch the Google Play Game Page for my game programmatically when the player hits this button from the game screen:
An example of the page I want to launch to is:
https://drive.google.com/file/d/0B8Xfkv7Sp0JzdzJiWWpFWG8zNHoydnMzWkwzZVJWZDJuUXZr/view?usp=sharing
Any thoughts/suggestions on doing this?
PS. I've just taken a random awesome game "BADLAND" as an example :). Hope that's okay!
It has been a while so I don't know if you found the answer already but I have been working on essentially the same thing today and figured I would share my solution. I found no sources on this online and ended up decompiling the app to look at what it expects for the intents to launch it.
Intent intent = new Intent();
//Clear the activity so the back button returns to your app
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//Manually specify the package and activity name
intent.setComponent(new ComponentName("com.google.android.play.games", "com.google.android.gms.games.ui.destination.api.ApiActivity"));
//Not really needed as default happens if you don't specify it.
intent.addCategory(Intent.CATEGORY_DEFAULT);
//You must specify the current players user. It ensures that Google Play Games is logged in as the same person.
intent.putExtra("com.google.android.gms.games.ACCOUNT_KEY", Games.Players.getCurrentPlayerId(googleApiClient));
intent.putExtra("com.google.android.gms.games.SCREEN", 1050); //"Magic" number from the source code for the about page
intent.putExtra("com.google.android.gms.games.GAME", Games.GamesMetadata.getCurrentGame(googleApiClient));
startActivity(intent);
Note that the page itself uses a hard coded number. I tested over several versions of Google Play Games and they worked but I still haven't found where the value is defined. You may also want to add in some error handling for cases such as Google Play Games not being installed.
Details on more pages such as profile compare
Github Gist of all pages
The accepted answer is deprecated now. Do the following:
Create these methods in AccountUtil.class (Or whatever you may call it):
fun getGamesAccount(): GoogleSignInAccount? {
return GoogleSignIn.getLastSignedInAccount(app)
}
fun getGamesPlayerInfo(): Task<Player>? {
val account = getGamesAccount()
return if (account != null) {
Games.getPlayersClient(app, account).currentPlayer
} else null
}
fun getPlayerProfileIntent(player: Player): Task<Intent>? {
val account = getGamesAccount()
return if (account != null) {
Games.getPlayersClient(app, account).getCompareProfileIntent(player)
}else null
}
Then you can get the profile intent like this:
accountUtil.getGamesPlayerInfo()?.addOnSuccessListener { player ->
accountUtil.getPlayerProfileIntent(player)?.addOnSuccessListener {
startActivityForResult(it, PROFILE_REQUEST_CODE)
}
}
companion object {
const val PROFILE_REQUEST_CODE = 23423
}
Can anyone tell me how to check if the android phone has a front camera too? I'd tried to use some help form https://docs.google.com/View?id=dhtsnvs6_57d2hpqtgr but Camera camera = FrontFacingCamera.getFrontFacingCamera(); sometimes works sometimes not.
Any help please?
Can anyone tell me how to check if the android phone has a front camera too?
There is no API for this, at least through Android 2.2. Sorry!
I'd tried to use some help form https://docs.google.com/View?id=dhtsnvs6_57d2hpqtgr but Camera camera = FrontFacingCamera.getFrontFacingCamera(); sometimes works sometimes not.
That is for two specific models of phones, not for Android devices in general. With luck, the upcoming Gingerbread release will add built-in support for front-facing cameras.
In the meantime, you need to get the instructions (like the one you linked to) from each and every device manufacturer and attempt to follow them.
private boolean hasFlash() {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
try {
if(camManager==null)
camManager=(CameraManager)getSystemService( CAMERA_SERVICE );
String cameraId = camManager.getCameraIdList()[1];
CameraCharacteristics cameraCharacteristics = camManager.getCameraCharacteristics( cameraId );
return cameraCharacteristics.get( CameraCharacteristics.FLASH_INFO_AVAILABLE );
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}