以编程方式从Android转到miracast接收器的步骤 [英] Steps to programmatically cast from android to miracast receiver

查看:2996
本文介绍了以编程方式从Android转到miracast接收器的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个应用程序,该应用程序将从Android手机将屏幕投射到通过miracast的电视。我使用的是HDMI软件狗,因为有问题的电视本身并不支持miracast。我一直在尝试代码在这里,但它需要一个应用程序ID,我已这些步骤。我的问题是,说明似乎表明,我需要注册miracast加密狗,所以它会谈到一个未发布的'调试'应用程序。但是,仅提及Google Cast设备,并且与miracast不是相同的协议。我还需要注册加密狗吗?



有没有一种更简单的方法通过miracast以编程方式转换到设备?



我使用的是Android 5.1,如果相关的话。



EDIT :进一步研究后,我意识到Google Cast使用的是与Miracast完全不同的协议,因此所有关于加密狗的说法都是不相关的。完全不需要注册在Android中做Miracast。问题是API是隐藏的,详情请参阅下面的答案。

解决方案



您需要使用

WifiDisplay API 的隐藏部分。 a>使一切成为可能。此文件包含了如何使用API来投射显示。它会出现,Google会在某些时候公开发布,但它



如何访问隐藏的API
$ b

要使用隐藏的API,此指南提供了一个很好的介绍。如果你使用的是API 22+,那么该指南将不会工作,因为android.jar的格式已经改变,并且classes.dex已经拆分成多个文件。因此,在这种情况下,建议更准确。不是那些 framework-classes2.dex 必须的ps也要做;它不是可选的。



最新版本的 dex2jar 工具无法将.dex文件从API 22放入罐中。该解决方案由作者此处提及。我选择补丁工具,而不是改变dex,因为这对我没有工作。简单地改变作者提到的行抛出一个RuntimeException到:

  return TypeClass.INT; 

如何获取使用隐藏API的权限 b
$ b

一旦这一切完成,下一步就是给你的应用程序 CONFIGURE_WIFI_DISPLAY 权限。很抱歉,您可以在这里查看系统级保护。这意味着您的应用程序必须使用与系统相同的密钥进行签名才能使用此权限。因此,除非您有Google的私人金钥,否则您无法让应用程式在一般Android手机上执行。我的解决方案是构建一个自定义版本的CyanogenMod(使用指南),权限从系统更改为正常'。这消除了对签名任何东西的麻烦。我也对 CONTROL_WIFI_DISPLAY 权限也这样做。虽然我不完全确定这是必要的,它不伤害。这两个权限都位于 frameworks / base / core / res / AndroidManifest.xml 中。更改第2161-2169行:

 < permission android:name =android.permission.CONFIGURE_WIFI_DISPLAY
android:protectionLevel =signature/>
< permission android:name =android.permission.CONTROL_WIFI_DISPLAY
android:protectionLevel =signature/>

To:

 code>< permission android:name =android.permission.CONFIGURE_WIFI_DISPLAY
android:protectionLevel =normal/>
< permission android:name =android.permission.CONTROL_WIFI_DISPLAY
android:protectionLevel =normal/>

然后正常构建CyanogenMod。我可以确认这是工作,但这限制了您的应用程序运行在已安装此自定义版本的CyanogenMod的设备上。此外,在Android手机上安装CyanogenMod通常会使保修失效。


I'm trying to write an app that will start casting the screen from an Android phone to a TV via miracast. I'm using an HDMI dongle since the TV in question doesn't natively support miracast. I have been trying the code here, but it needs an Application ID which I have got following these steps. My question is, the instructions seem to indicate that I need to register the miracast dongle so it will talk to an unpublished 'debug' app. However, only Google Cast devices are mentioned and that isn't the same protocol as miracast. Do I still need to register the dongle?

Is there a simpler way of programmatically casting to a device via miracast? A requirement is no user interaction, so I can't just display a cast button.

I'm using Android 5.1 if that's relevant.

EDIT: After further research, I realized that Google Cast uses a completely different protocol from Miracast, and thus all the talk of registering the dongle is irrelevant. No registration is required at all to do Miracast in Android. The issue is the API is hidden, see my answer below for details.

解决方案

So this is possible, but only on custom versions of Android due to permission problems.

What you need to use

The hidden part of the WifiDisplay API makes it all possible. This file contains examples of how to use the API to cast the display. It appears that Google will release it publicly at some point, although it's still hidden in the latest master of API 23 as far as I can see.

How to access the hidden API

To use hidden APIs, this guide provides a good introduction. If you're using API 22+ however, then that guide won't work as the format of android.jar has changed and classes.dex has been split across multiple files. So this advice is more accurate in that case. Not that the ps about framework-classes2.dex must also be done; it isn't optional.

The latest version of the dex2jar tool fails to turn the .dex file from API 22 into a jar. The solution is mentioned by the author here. I opted to patch the tool instead of changing the dex, as that didn't work for me. Simply change the line the author mentions from throwing a RuntimeException to:

return TypeClass.INT;

How to get permission to use the hidden API

Once that is all done, the next step is giving your app the CONFIGURE_WIFI_DISPLAY permission. Unfortunately, as you can see here, it has system-level protection. This means that your app must be signed by the same key as the system to use this permission. So unless you have Google's private key, you can't have your app run on normal Android phones. My solution was to build a custom version of CyanogenMod(using this guide), with the permission changed from 'system' to 'normal'. This eliminates the need to bother with signing anything. I also did the same for the CONTROL_WIFI_DISPLAY permission. Whilst I'm not entirely sure this is necessary, it doesn't hurt. Both these permissions are located in frameworks/base/core/res/AndroidManifest.xml. Change the lines 2161-2169 from:

<permission android:name="android.permission.CONFIGURE_WIFI_DISPLAY"
    android:protectionLevel="signature" /> 
<permission android:name="android.permission.CONTROL_WIFI_DISPLAY"
    android:protectionLevel="signature" />

To:

<permission android:name="android.permission.CONFIGURE_WIFI_DISPLAY"
    android:protectionLevel="normal" /> 
<permission android:name="android.permission.CONTROL_WIFI_DISPLAY"
    android:protectionLevel="normal" />

Then build CyanogenMod as normal. I can confirm this does work, but this limits your app to running on devices which have this custom version of CyanogenMod installed. Furthermore, installing CyanogenMod on an Android phone will generally invalidate the warranty.

这篇关于以编程方式从Android转到miracast接收器的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆