I have an app that uses google voice speech recognition. It works perfectly, but the voice capture popup freezes sometimes (see snapshot) I have narrowed down the problem to the point where as long as a commercial app called X is active in the background, the google voice popup freezes. As soon as I close app X by swiping it away, my app's speech recognition works perfectly again.
This is the code I use to launch the speech recognition popup:
#Override
protected void onResume() {
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE,app.getDemoLanguageCode());
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, app.getDemoLanguageCode());
speechIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, app.getDemoLanguageCode());
speechIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
speechIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1);
}
static void openGoogleASR() {
thisActivity.startActivityForResult(speechIntent, SPEECHRECON_CODE);
}
This is how the speech recognition popup looks like when it freezes while app X is active in the background:
Do you know how to properly initialize my speech recognition to make it robust against other misbehaving apps?
Related
I am creating an android application and want to show Toast on mouse right click and left click.
The default listner is
public boolean onGenericMotionEvent(MotionEvent event) {
if(event.getActionButton() == MotionEvent.ACTION_UP){
Toast.makeText(this, "Left click", Toast.LENGTH_SHORT).show();
}
}
It runs perfectly when my app is opened. How can I do it in background (say while using WhattsApp)?
Thanks in advance :)
When your app is in the background, the way to make it work is by using a Service. Start the service when your app is onPause (on onStop for API level above 23). And in the onStart, check if your Service is running and stop it.
If you are using Fragment then adapt this according to the Fragment's lifecycle.
I have to create an app, which detects user inactivity, and then start activity which displays some videos with WebView, and then when displaying with WebView is finished, it has to play videos from SDCard. I've already handled part with WebView and SDCard (with JavaScriptInterface etc.)
This application has to work with API 19 all the way to the newest one.
The question is - Is there a possibility to detect if user is inactive and start my application, or keep the app running in background, and then start activity in the foreground after the user becomes inactive for certain time?
I'm not trying to play ads, when user is not looking at his screen. Application is for my client, who have stores with all kind of electrical equipments, including smartphones. The goal is to play video presentations with hardware details specific for each smartphone (informations about processor, ram, camera, screen etc.).
In short: I have to make an app which is similar to "Demo Apps" created for example by Samsung (playing some kind of presentations on screen).
So far I've read and tested things like:
1) BroadcastReceiver with combination of ACTION_SCREEN_OFF / ACTION_SCREEN_ON events.
Receiver works properly, I can detect this event and then start activity, but... The screen is already off so i can't see the displayed activity - it's visible running in the foreground after unlocking the phone. Is there a way to unlock the phone when the event is received?
That's my code so far.
EventReceiver Class:
class EventReceiver: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
StringBuilder().apply {
append("Action: ${intent.action}\n")
append("URI: ${intent.toUri(Intent.URI_INTENT_SCHEME)}\n")
toString().also { log ->
Log.d(TAG, log)
Toast.makeText(context, log, Toast.LENGTH_LONG).show()
}
}
if (intent.action == Intent.ACTION_SCREEN_OFF) {
val i = Intent(context, MainActivity::class.java)
context.startActivity(i)
}
}
}
MainActivity Class:
val br : BroadcastReceiver = EventReceiver()
val filter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION).apply {
addAction(Intent.ACTION_SCREEN_OFF)
addAction(Intent.ACTION_SCREEN_ON)
addAction(Intent.ACTION_BOOT_COMPLETED)
}
2) Foreground Services - I read that this is a great way to make some asyc stuff in the background and show notifications to user. Is there a way to start the activity with it?
3) Job Scheduler
4) Daydream / Dream Service - it actually works great with almost every API and manufacturer, but.. there's no way to set the app as Screen Saver on Huawei/Honor smartphones, at least from phone settings, I've read that this is possible with ADB etc. but this is not an option that I can use here.
It seems that none of these fullfill my expectations.
I have a simple Android application which contains a WebView to load my Web_Based application and a VideoView to play Video (using HTTP protocol) and Multicast Stream (Live TV using UDP Protocol).
The Web_Based application, Video Server and Live TV Server are in a local Server (Ubuntu 12.04) and so my Android Application is connected to them locally with Ethernet Cable (Not via Internet).
Also my Android Device is a STB with Android Version 6.
The Android application is developed to play Video or Live TV when it is starts just by clicking on a button.But the issue is that JUST SOMETIMES, when I turn the STB on (and instantly starting the Android application), there is a delay for about 30 seconds to start Live TV. This issue is not happening for Video at all.
A sample of Live TV stream is udp://239.0.0.1:1234
A sample of Video url is http://192.168.200.235/test.mp4
// This is a pert of my main function to play UDP Stream
PlayerActivity.videoView.stopPlayback();
final Uri video = Uri.parse("udp://"+url.replaceAll("\\s+",""));
PlayerActivity.getInstance().runOnUiThread(new Runnable() {
#Override
public void run() {
PlayerActivity.videoView.setVisibility(View.GONE);
PlayerActivity.videoView.setVisibility(View.VISIBLE);
PlayerActivity.videoView.setVideoURI(video);
PlayerActivity.videoView.start();
PlayerActivity.videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
#Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.e("ERROR LOG FOR UDP STREAM",":( I don't get any error here !");
return false;
}
});
}
});
Although Android can play UDP stream, but it's not built for this. So, it's better to use HSL or RTMP protocol for live stream playback and also for video file You can use HLS.
In HTML5WebView.java (pastebin link)(source) I have:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
System.out.println("TAG - BACK PRESSED IN WEB VIEW");
return super.onKeyDown(keyCode, event);
}
And in the activity that starts the web view I have:
#Override
public void onBackPressed() {
System.out.println("TAG - BACK PRESSED IN WEB PLAYER ACTIVITY");
super.onBackPressed();
}
Now when I'm playing an embedded youtube video normally (not fullscreen), both methods are called when I press the back button. When I put the video into fullscreen mode (using the youtube player fullscreen button), none of the methods are called. My only guess is, the back button is being consumed by the web view to undo the fullscreen action (but even that doesn't work).
I am trying to get the back button to immediatly kill the web view, even if there is a video in fullscreen mode.
See the problem in action here, had to post it externally because the gif > 2MB
If I was you I would delete the embed play of youtube video's or ask google that won't be seen as abuse. Because the embed play of youtube video's can be seen as a abuse of this:
Your app violates our Device and Network Abuse policy by downloading,
monetizing, or otherwise accessing YouTube videos in violation of the
YouTube Terms of Service or YouTube API Terms of Service.
More Info: https://play.google.com/about/privacy-security/device-network-abuse/ https://www.youtube.com/static?template=terms
For example, your app contains: YouTube background play functionality
This is a violation of the YouTube Terms of Service.
That is what I got in my experience because I also made a app where people could watch some YT embed video's but after some updates the app wouldn't be update becuase I got this error that it is abuse so I am warning you that's all.
i use this method to record video from front camera:
Recording video via Mediarecorder
it works fine in my Nexus 4 but some people says that there is a lot of phones that their front camera cant record video and they only can take pictures. My Android App functionality based on recording video from front camera and my question is that is this true that some phones can't record video via front camera? and how i can detect this and inform user?
Try calling some code like this
CameraInfo cameraInfo = new CameraInfo();
if (cameraInfo.facing = CameraInfo.CAMERA_FACING_FRONT) {
//do your code?
} else {
//alert the user via toast or dialog
}
no built in way to figure it out though.
EDIT:
should work on API 9 and above.
maybe try calling these methods to first get a camera object, then check to see if there is a camcorderProfile available for the front facing camera?
hasProfile (int cameraId, int quality)
setCamera(camera);