您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Android >> Android JNI回调Java GPS回调 GPS数据上报 mContext发送广播

Android JNI回调Java GPS回调 GPS数据上报 mContext发送广播

来源:网络整理     时间:2016/6/5 3:09:49     关键词:

关于网友提出的“Android JNI回调Java GPS回调 GPS数据上报 mContext发送广播”问题疑问,本网通过在网上对“Android JNI回调Java GPS回调 GPS数据上报 mContext发送广播”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:Android JNI回调Java GPS回调 GPS数据上报 mContext发送广播
描述:

   本人在工作中需要模仿GPS通路为android系统添加一个硬件模块(基于串口),目前已经是想从应用程序调用底层的JNI接口等,从而实现往串口发送数据。但是目前我想提供一条从Hardware层到JNI再到frameworks层的通路,并在frameworks层发送广播消息,使应用程序能够收到这个广播消息并作出相应处理,现在从hardware层到frameworks层已经打通,但是在frameworks发送广播消息时报错(空指针异常),详细如下:
   系统GPS源码:
JNI:


static void location_callback(GpsLocation* location)
{
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    env->CallVoidMethod(mCallbacksObj, method_reportLocation, location->flags,
            (jdouble)location->latitude, (jdouble)location->longitude,
            (jdouble)location->altitude,
            (jfloat)location->speed, (jfloat)location->bearing,
            (jfloat)location->accuracy, (jlong)location->timestamp);
    checkAndClearExceptionFromCallback(env, __FUNCTION__);
}

frameworks:

private void reportLocation(int flags, double latitude, double longitude, double altitude,
            float speed, float bearing, float accuracy, long timestamp) {
        if (VERBOSE) Log.v(TAG, "reportLocation lat: " + latitude + " long: " + longitude +
                " timestamp: " + timestamp);
...
...
...
Intent intent = new Intent(LocationManager.GPS_FIX_CHANGE_ACTION);
intent.putExtra(LocationManager.EXTRA_GPS_ENABLED, true);
mContext.sendBroadcast(intent);
updateStatus(LocationProvider.AVAILABLE, mSvCount);

这个mContext是在构造函数中实现的

public GpsLocationProvider(Context context, ILocationManager locationManager) {
        mContext = context;

我的代码:

BtNative(Context context) {
Log.i(TAG, "--------Constuct BtNative OK----------");
mContext = context;
                if(mContext == null)
{
        Log.i(TAG, "---mContext == NULL---");       
}
else
{
        Log.i(TAG, "---mContext != NULL---");
}
private void reportPhone(String str) {
Log.i(TAG, "-callbacks---");
Log.i(TAG, "---" + str + "----");
Intent intent = new Intent(ACTION_BT_INCALL);
Log.i(TAG, "---Intent new ok!---");
if (mContext == null) {
Log.i(TAG, "---mContext == NULL---");
} else {
mContext.sendBroadcast(intent);
}
}

当串口有相应的数据过来时会调用到reportPhone,但是mContext总是为null,我不知道这是为什么,感觉有点棘手
故发此贴,请求牛哥给予帮助

以上介绍了“Android JNI回调Java GPS回调 GPS数据上报 mContext发送广播”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1521550.html

相关图片

相关文章