Android HDMI- CEC Check TV Power status - android

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.

Related

How to check for DolbyDigtal (AC3) support on device?

I'm trying to understand: is there a way to check if Android device supports DolbyDigital (AC3).
I found a broadcast action ACTION_HDMI_AUDIO_PLUG that indicates wether HDMI connected or not. Also it sends an array of all the supported encodings via the value EXTRA_ENCODINGS. But, as I understand, those are the values that the TV supports, not the Android device itself.

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.

How to check if Samsung Gear 2 is paired with Android device programmatically?

I am using Tizen SDK for Wearable from samsung-gear site in order to communicate a provider android application with Samsung Gear 2 device. I am able to send notifications to gear and once I run the consumer application on gear 2, I am able to transfer data between the watch and my Android phone as well.
What I am trying to do is to check within the Android application if the phone is paired with Gear 2. Something as simple as creating a communication object using the accessory service and calling a method like isPaired()?:
CommunicationObject commObject = new CommunicationObject(Communication parameters);
// I am assuming some connection call like commObject.connect() should be invoked first
// where I can check for it's result afterwards such as
if(commObject.isPaired())
{
// do something
}
I think SDK examples such as consumer/provider application they provide on their site already assume that the device is paired, hence they show how to transfer data between phone and the gear watch. Yet I am seeking something as simple as asking the phone if it's paired with a gear device, which should be the prerequisite for transferring the data, which is done automatically by Samsung Gear Manager I believe right now.
Note: For the case of example provider/consumer applications, one can just check if any connection is available using the code in them. But the data transfer connection enabled only when I manually start the consumer app from the gear device, otherwise it acts like gear device is not paired even though it is.
I believe this is not the most popular topic these days so I will post what I came up with as an answer although I doubt anyone will need it, without being perfect, it's the closest way I could get to my goal using the available documentation.
I should also mention that this slide helped me stay on track as well.
In my solution, there must be an active 2-way connection between the gear widget(consumer/.wgt) and the host side application(provider/.apk) as in the example application provided by Samsung(Hello Accessory) at all times, at least during the time where I wanted to check for the pairing condition. The documentation refers to it as:
Hello Gear is a simple application that consists of:
Host-side application(provider) : HelloAccessoryProvider.apk
Wearable-side Application(consumer) : HelloAccessoryConsumer.wgt (Web app)
See that both sides have some xml configuration and Android requires specific permissions which are explained in detail in Hello Gear documentation.
This 2 way communication is provided by the Samsung Accessory Framework on the network layer(through Samsung Accessory Protocol, SAP) given that both sides implement the same Accessory Service Profile, again, configured via the xml files on both ends(service name, channel id etc.).
Android side implements the protocol as a service, extending the SAAgent abstract class. Then the widget on gear side application(.wgt) can invoke the SAAgent callbacks and provider/consumer communication is handled through SASocket objects claimed on both ends over the predefined channel in the xml configuration files.
Please note that this communication has to be initialized on both ends, in my case I had to open the widget application once on Gear(I believe there should be a way to start the gear widget via an intent or notification, somehow, but I could not find yet) after the Android application has started, here started means that SAAgent service is up and bound to an Activity, being eligible to receive callbacks and send state messages to the rest of the application via broadcasts. Such as the number of active connections, or any data transmission between the gear socket and Android application can be done this way.
Note that if you don't have to transfer data between the gear widget and the Android application, you may just be OK with the notifications. The only requirement to send notifications to the Gear from Android applications seems to be that the Gear is paired with your phone and connected via Bluetooth. Then you can just send an intent as explained in more detail here in Section 6. All you need should be the permission:
com.samsung.wmanager.ENABLE_NOTIFICATION
and some metadata definition in your ApplicationManifest.xml file explained in the same section.
<meta-data
android:name="master_app_packagename"
android:value="com.example.gearMasterApp"/>
<meta-data
android:name="app_notification_maxbyte"
android:value="300 "/>
And here is the sample code for intent, in order to send notifications to the Gear:
public static final String ALERT_NOTIFICATION =
“com.samsung.accessory.intent.action.ALERT_NOTIFICATION_ITEM”;
public static final int NOTIFICATION_SOURCE_API_SECOND = 3;
Bitmap bitmapImg;
// Put data to Intent
Intent myIntent = new Intent(ALERT_NOTIFICATION);
myIntent.putExtra("NOTIFICATION_PACKAGE_NAME", “com.example.gearApp”);
myIntent.putExtra("NOTIFICATION_VERSION", NOTIFICATION_SOURCE_API_SECOND);
myIntent.putExtra("NOTIFICATION_TIME", System.currentTimeMillis(););
myIntent.putExtra("NOTIFICATION_MAIN_TEXT", “Title Text”);
myIntent.putExtra("NOTIFICATION_TEXT_MESSAGE", ”Body text);
byte [] byteArray = convertResizeBitmapToByte(bitmapImg);
myIntent.putExtra("NOTIFICATION_APP_ICON", byteArray);
myIntent.putExtra("NOTIFICATION_LAUNCH_INTENT", “com.example.gearMasterApp”);
myIntent.putExtra("NOTIFICATION_LAUNCH_TOACC_INTENT", “com.example.gearSideApp”);
sendBroadcast(myIntent);
public byte[] convertResizeBitmapToByte(Bitmap bitmap){
Bitmap scBitmap = Bitmap.createScaledBitmap(bitmap, 75, 75, false);
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
scBitmap.compress(Bitmap.CompressFormat.PNG, 50, byteArrayStream);
return byteArrayStream.toByteArray();
}
Once the notification is read on the gear side, you can receive the intent action along with some optional parameters:
Intent Action :
"com.samsung.accessory.intent.action.UPDATE_NOTIFICATION_ITEM"
This could be another approach to check active communication with the Gear and your phone, but there is no guarantee that the notification will be read and my case did require to keep the Gear communication optional in order to allow the Android application continue it's tasks even though there is no active connection with the Gear.
About the original question, where I asked for a way to detect if the Gear is paired or not, I tried listing paired Bluetooth devices using getBondedDevices() method of Android's BluetoothAdapter but it shows that your Gear is paired even when your Gear is turned off, which was not enough for my needs and I did not find it logical. It's true though once your device is turned back on.
I'm happy with the above solution since it was enough for my needs, therefore I will accept my own answer.

How to implement a Android bluetooth paring without pop up a dialog to get a user permition?

These days , i implement a blue tooth paring function on android platform,say in details:
The master device is Google TV(3.2), the slave device is blue tooth keyboard,both are HID device.
The Keyboard can be easily put in to discoverable status, When the TV bootup first time ,In TV setup guide, i need to let the tv paring with keyboard,
As you know, in generall, enable bluetooth on TV side we need get the user permition, then can connect.Then my question happend is that i don't want to pop up a dialog to get permition, is there some body can tell me how to do ?
Thanks!
I found a simple way - in the Android code tree, in external\bluetooth\bluez\src\device.c:
/* If our IO capability is NoInputNoOutput use medium security
* level (i.e. don't require MITM protection) else use high
* security level */
if (capability == 0x03)
sec_level = BT_IO_SEC_MEDIUM;
else
sec_level = BT_IO_SEC_HIGH;
//david10000 add
if (device_is_david10000_BTDEV(device)) {
sec_level = BT_IO_SEC_MEDIUM;
}
This means we can low level the security to let your special device connect automatically.
Another way is you can program it to auto fill the passkey/pin etc. when you get the Android pair request.
If you have this problem, try this, it works for me.

Channel Listing in Google TV not showing channels

I'm testing Googl's 'Channel Changing Example' on my Sony Google TV.
I'm connected to a DVB (Digital Video Broadcasting) through the HDMI port.
When i'm running the example the number of retrieved channels is 0.
Just to be clear, I can see the TV channels using the 'Live TV' in the TV itself.
You need to make sure that your selected device has a channel lineup. Based on the fact that you're using DVB, I'm guessing you're not in the US, which means you aren't really using this in a supported country. However, you can fake it by going to Settings > Video input > Configured devices > (whatever your TV source is) > Edit channel lineup and then go through the prompts. This will download the list of channels for your connected set top box (again, this is probably not going to be your real lineup, but enough for you to test out the sample.

Categories

Resources