定制系统服务的上下文错误 [英] Context error of custom system service

查看:141
本文介绍了定制系统服务的上下文错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个与zigbee设备通信的系统服务.更新了API,创建了system.img,并在设备上刷新,并为Android编程制作了自定义SDK.

I have created a system service that communicates with a zigbee device. Updated APIs and created system.img and flashed on the device and made custom SDK for android programming.

在Mainactivity类中,

In the Mainactivity class,

try {
        ZigbeeManager zm = (ZigbeeManager) getSystemService(Context.ZIGBEE_SERVICE);
        zm.write("Hello World!\r");
    } catch (Exception ex) {
        Log.d(TAG, "Error in Zigbee Service: " + ex.toString());
    }

我在"Context.ZIGBEE_SERVICE"一词上遇到了错误.当我将光标放在它上面时,它会显示必须是:所有系统服务列表中的一个". 使用其他系统服务有效.像其他系统服务一样,Context.class文件中也提供了Zigbee服务.

I am getting an error over the words "Context.ZIGBEE_SERVICE". It says "Must be one of : list of all system services" when I put my cursor over it. Using other system services works. Also Zigbee Service is available in the Context.class file just like the other system services.

...
public static final String WIFI_SERVICE = "wifi";
public static final String WINDOW_SERVICE = "window";
public static final String ZIGBEE_SERVICE = "zigbee";

现在在设备上运行它.我在logcat上收到此错误消息.

Now when running it on the device. I get this error message on the logcat.

01-01 12:09:24.126 6874-6874/com.jcxmej.uartcontrol D/UARTControl: Error in Zigbee Service: java.lang.NullPointerException: Attempt to invoke interface method 'int android.os.IZigbeeService.write(java.lang.String)' on a null object reference

该对象为Null.是否需要初始化它,但是如何?但我认为它是Null,因为上下文未正确链接.我如何摆脱上下文错误.或在上下文中正确添加Zigbee服务.

The object is Null. Does it need to be intialised but how? But I think it is Null because the context is not linked properly. How do I get rid of the Context error. Or properly add Zigbee service in the Context.

我以此为参考. https://github.com/nayobix/add-new-hardware -hal-android-5-lollipop

推荐答案

在框架内注册系统服务(假设您已经构建了服务)时,除了添加服务名称,则需要执行以下步骤:

When register a system service inside the framework (Assuming you already built the service) you need to do more than add the String name of your service, you need to perform the next steps:

  1. Register your service in SystemServer.java (Dig to the code and add it to the try/catch List of all services).
  2. Add your AIDL to frameworks/base/core/java/android/os/.
  3. Add your serivce file name to the build inside frameworks/base/Android.mk .

您可以在这篇很棒的文章中查看更多信息.

You can see more info in this great article.

这篇关于定制系统服务的上下文错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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