How to know when input TV changed from HDMI1 to HDMI2 programmatically? - android

I am developing an app for "GoogleTV" and "Chromecase with GoogleTV". My app needs to know when HDMI input changed to pause the video stream. I have found the following information about it for FireTV:
https://developer.amazon.com/docs/fire-tv/handling-hdmi-events.html#available-apis
I tried the same implementation for GoogleTV running in Chromecast. The problem is that any intent is received by the listener when input TV changes from HDMI1 to HDMI2 (or broadcast TV input). Events are received only when TV is turned ON/OFF.
Is there any way to know when the TV input changes in Chromecast?

Related

How to receive action from bluetooth device (External Mic WALKY TALKY) on android?

I have some bluetooth device for android with name INRICO BT01.
I want my application to detect the PTT button available on the device when it is being pressed.
I have tried using the receiver with filter action: ACTION_MEDIA_BUTTON. But there was no response whatsoever.
This some example that I use before.
Thank you in advance for your help.

Android HDMI- CEC Check TV Power status

I have check Android HDMI CEC
Find out HDMI Cable is connected or not using below code:
private boolean isHdmiCableAttach() {
// The file '/sys/devices/virtual/switch/hdmi/state' holds an int -- if it's 1 then an HDMI device is connected.
// An alternative file to check is '/sys/class/switch/hdmi/state' which exists instead on certain devices.
File switchFile = new File("/sys/devices/virtual/switch/hdmi/state");
if (!switchFile.exists()) {
switchFile = new File("/sys/class/switch/hdmi/state");
}
try {
Scanner switchFileScanner = new Scanner(switchFile);
int switchValue = switchFileScanner.nextInt();
switchFileScanner.close();
return switchValue > 0;
} catch (Exception e) {
return false;
}
}
Now I want to find out TV Power on/off using HDMI-CEC
I cannot found any help from site I tried to get help from LibCEC but how to integrate LibCEC in app?
Can any one help me to get power status or setup LibCEC
Actually, Android TV already have this feature wherein it provides developer APIs for third-party TV inputs. As mentioned in TV App,
Android TV provides developer APIs for third-party TV inputs, enabling installed apps to deliver software channels into the live TV experience. To ensure a compatible Android device implementation, the system TV App has some responsibilities regarding surfacing third-party TV inputs and channels to the user.
TV integration guidelines are listed below:
Because each country has broadcast-specific requirements (MHEG, Teletext, HbbTV, and more), manufacturers are expected to supply their own solutions for the broadcast app, for example:
MHEG: native stack
Teletext: native stack
HbbTV: webkit modification by Opera browser
In the Android L release, Android TV expects device manufacturers to use systems integrators or the Android solutions for regional TV stacks, pass the surface to TV software stacks, or pass the necessary key code to interact with legacy stacks.
Here’s how the broadcast app and TV App interact:
The TV App is in focus, receiving all keys.
The TV App passes keys (e.g. Red button) to the TV Input device.
The TV Input device internally integrates with legacy TV stack.
On receiving an activation keycode (e.g. Red button), the TV Input device activates broadcast apps.
A broadcast app takes focus in the TV App and handles user actions.
For a more detailed information, please try going through TV Input Framework and you may want to also check the CEC integration on Android TV as shown in the documentation.

HDMI-CEC and the Chromecast

I know that the Chromecast is being launched automatically with any app that has the "Cast" icon. That means we can be using directly a phone or tablet without the TV controller to initiate a connection.
HDMI-CEC has something to do with this.
TV switches automatically.
What I would like to know is if it would be possible to end the connection with the Chromecast and not land on the Chromecast homepage like right now. I would like to come back on the signal that I had before the "Cast", which could be a channel of the TV for example, and this, without the TV controller.
Currently, it is impossible to come back without not using the "Source" button of the TV controller.
Does anyone have a solution that could help me?
So, in CEC there is a provision to tell the TV you're done. It's called <Inactive Source>.
Chromecast uses <Active Source> to turn on the TV and change inputs it it.
It could use <Inactive Source> to indicate to the TV that it has stopped sending video.
<Inactive Source>, however, varies by TV.

Android Bluetooth SCO with Nissan car radio

Before we get to the details, a little context:
Car: Nissan Note (UK 2011 Model)
Device: Nexus 4
OS: Android 4.3 Stock
I'm trying to create an app to do speech recognition and synthesis in my car while the phone is connected over bluetooth. The car audio system does not provide it's own voice recognition, but instead delegates this to the phone by triggering an intent android.intent.action.VOICE_COMMAND
The default app on the device for handling this is the Google Search app, which has a specific activity for hands-free dialling. This app has terrible speech recognition but does demonstrate how the system is supposed to work - when activated the car displays "Voice recognition active" on the phone screen while the app is running, and then hides it when the app exits.
The problem I have is that while I can make this label appear by calling AudioManager.startBluetoothSco() and thus play audio through the car speakers and record it through the car microphone, but AudioManager.stopBluetoothSco() does not disable this mode in the car, and it remains displaying 'Voice recognition active'. This is a problem since the car will not then launch the app until the bluetooth connection has been closed and re-opened.
My experiments have verified that it is AudioManager.startBluetoothSco() which enables the mode in the car, and that AudioManager.stopBluetoothSco() appears to have the effect of changing the ambient sound produced by the car (a very faint hiss usually heard when the audio system is active will stop when this command is issued) but no other effect is seen.
I am unsure if something else is activated implicitly with the call to AudioManager.startBluetoothSco() which must then be implicitly stopped, but I'm currently out of ideas for what to try.
After a lot more research I came across this: http://developer.android.com/reference/android/bluetooth/BluetoothHeadset.html#stopVoiceRecognition%28android.bluetooth.BluetoothDevice%29
which would appear to be related to the problem. After calling startVoiceRecognition and stopVoiceRecognition as appropriate, things appeared to return to their normal state.

How to capture or reroute navigation voice stream

There is a problem when using Google Navigation on Android with a Bluetooth device. Navigation sends the audio for the turn-by-turn instructions over the A2DP stream. I have a Motorola T605 Bluetooth car kit and it supports HFP and A2DP. I often just listen to the old fashioned car radio though. In this scenario I never hear turn-by-turn directions because my live A2DP stream is being sent to the radio AUX input but I am listening to the radio instead. My app has a feature where it reads out SMS messages to me. I have it set up so you can pick the stream you want to use for this. I prefer using AudioManager.STREAM_VOICE_CALL since it uses a dedicated separate speaker on the T605.
I have looked into a few ways to handle this:
1) Reroute notifications to Bluetooth SCO instead of A2DP. I have not fund a way to do this. I am able to send TTS messages I create over this path and it works great (I have an SMS reader built into my app). I tried activating SCO but the turn-by-turn instructions stream moves to the phone internal speaker instead of the voice call stream like I would prefer.
2) Capture the navigation messages and echo them back over the SCO path. I can't find a way to intercept or capture the navigation stream though. Does Google Navigation use the TTS engine or its own methods to create the voice output? It would be great to just get the directions in a text string since I could easily send that to the TTS engine and route it where I want like I do with SMS strings.
You can see my app source here: http://code.google.com/p/a2dpvolume/
Any thoughts?
Unfortunately I think you're SOOL when it comes to rerouting the navigation messages to BT SCO. I would expect the navigation app to use either the TTS or NOTIFICATION stream type to play the messages, and both of those stream types follow the MEDIA routing strategy (for NOTIFICATIONs that is at least typically true when there's no active voice call).
Although the behavior is up to each vendor to decide, my guess is that you'll find that in most implementations streams that follow the MEDIA routing strategy won't ever be routed to BT SCO, except during an ongoing voice call that is routed to BT SCO.
The best you could do in terms of routing is to force the routing to the loudspeaker, or to "anything but A2DP" (which means wired headset if one is attached, or the loudspeaker otherwise).
Here's how you could do that (I haven't verified that this works on every phone out there):
Class audioSystemClass = Class.forName("android.media.AudioSystem");
Method setForceUse = audioSystemClass.getMethod("setForceUse",
int.class,
int.class);
// 1 == FOR_MEDIA, 10 == FORCE_NO_BT_A2DP (FORCE_SPEAKER would be 1).
setForceUse.invoke(null, 1, 10);

Categories

Resources