本人在工作中需要模仿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,我不知道这是为什么,感觉有点棘手
故发此贴,请求牛哥给予帮助
系统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,我不知道这是为什么,感觉有点棘手
故发此贴,请求牛哥给予帮助
解决方案 »
- 怎么把imagview里的图片从左到右逐渐画出来?
- 请问Android 上层应用里的Java程序的消息怎么打印到串口里?
- android 调用拨号器拨号出错
- 跪求解决方法
- 使用ndk开发android游戏,大家都使用什么声音库,openSL,openAl, soundPool
- 求助:如何在android中编辑PDF,即点击手机屏幕,获取对应在PDF文件上的坐标
- 如何增加一个统Setting的界面,在不修改系统Setting源码的情况下
- Android旧版本问题
- android联系人
- 请教,如何设置listview的上下文菜单样式,让他可以完全显示出来
- 请问html5和java开发android有什么区别,是不是html5流行以后就不用java来开发android了?
- 在Eclipse中开发安卓为什么那么卡?
你的调用关系没仔细看,头大
private final Context mContext;
private final ILocationManager mLocationManager;
private Location mLocation = new Location(LocationManager.GPS_PROVIDER);mContext好像只能静态定义,然后就是在构造函数里面去赋值这些都是源码里面的东西 不可能全部都贴出来,如果可以看看GPS框架源码帮我分析分析
Email:[email protected]谢谢了