本人在工作中需要模仿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,我不知道这是为什么,感觉有点棘手
故发此贴,请求牛哥给予帮助
解决方案 »
- 想往android模拟器的"/data/"目录下新建一个.txt文件,可是程序运行后没有创建文件也不报错,不知怎么回事。
- android andengine游戏引擎
- 请教android数据库操作的问题
- 考勤表
- 如何在状态栏上增加一个截屏按钮,截屏具体实现方法?
- 求助 关于JNI中 CALL XXX METHOD方法的参数
- handler如何控制更新某个控制
- 百度地图 涉及 到 公交线路查询怎么搞?跨市呢?县里呢?
- 两个时间控件的时间没有触发 求助
- onKeyUp
- 请问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]谢谢了