Huawei Watch 2 NFC FEATURE not available?. Android Wear 2.0

好久不见. 提交于 2019-11-29 07:58:30

Based on this documentation, NFC feature is supported in Huawei Watch 2 and it also features Android Wear 2.0.

However, the error java.lang.UnsupportedOperationException means that the method isn't implemented yet by the framework authors, so you might contact the support team for clarifications. See this link.

In case you want to create a prototype which makes use of the NFC feature on a Huawei Watch 2 you could circumvent this bug by forcing the feature flag to true.

First create a function which is able to set a static property through reflection:

fun setStaticValue(className: String, fieldName: String, newValue: Any) {
    val field = Class.forName(className).getDeclaredField(fieldName)

    field.setAccessible(true)

    val oldValue = field.get(Class.forName(className));

    field.set(oldValue, newValue);
}

Then use the function just before you are calling a method which tests for the feature flag like this:

setStaticValue("android.nfc.NfcAdapter", "sHasNfcFeature", true)

I don't think this hack will be accepted for released apps though, but I was able to recognize tags using this method.

I've also send a bug report to Huawei, so let's hope they will fix it.

For more information using reflection see: http://blog.sevagas.com/?Modify-any-Java-class-field-using-reflection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!