Hi All,
In my Android project I am reading a data from hardware device. I have
Service class which contains a thread reading continuously data from
hardware. while reading data from hardware I will check true = 1 or false
= 0 values. My code is like below,
public class MyService extends IMyservice.Stub{
class MyThread extends Thread{
public void run(){
int value = dataFromHardware();
updateValueToUi(value);
}
}
}
The above class in in a path of AOSP:
frameworks/base/services/java/com/android/server/MyService.java
In the above code the thread will start when MyService class gets a event
from user and it reads data from hardware giving value. Now I want that
value to pass to UI. For that I am creating updateValueToUi(value) method
so that I can Broadcast it to user. Here I dont know how to broadcast above
value to UI. Compared with other code and I tried following mechanism to
pass value to UI but it's giving NullpointerException
Here is a code,
public void updateValueToUi(int value){
Intent intent = new Intent(Intent.ACTION_VERIFY_VALUE);
int myValue = value;
intent.putExtra("verifyKey", myValue);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
}
The value 'ACTION_VERIFY_VALUE' I defined in Intent.java class. and
receiving in application side like below
public BroadcastReceiver myReceiver = new BroadcastReceiver{
public void onReceive(Context context, Intent intent){
if("android.intent.action.ACTION_VERIFY_VALUE".equals(intent.getAction())){
updateVerifyValue(intent);
}
}
myMethod(){
verifyFilter = new IntentFilter();
verifyFilter.addAction(Intent.ACTION_VERIFY_VALUE);
context.registerReceiver(myReceiver, verifyFilter);
Toast.makeText(context, "verify clicked", 30).show();
}
}
The above code giving me below eroor :
FATAL EXCEPTION: main
E/AndroidRuntime( 3934): java.lang.NullPointerException
E/AndroidRuntime( 3934): at
android.app.ActivityManagerProxy.registerReceiver(ActivityManagerNative.java:2097)
E/AndroidRuntime( 3934): at
android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1338)
E/AndroidRuntime( 3934): at
android.app.ContextImpl.registerReceiver(ContextImpl.java:1306)
E/AndroidRuntime( 3934): at
android.app.ContextImpl.registerReceiver(ContextImpl.java:1300)
E/AndroidRuntime( 3934): at
android.content.ContextWrapper.registerReceiver(ContextWrapper.java:423)
E/AndroidRuntime( 3934): at com.example.biometricclient.BioClient$2.onClick(
BioClient.java:97) // my class in app layer
E/AndroidRuntime( 3934): at android.view.View.performClick(View.java:4202)
E/AndroidRuntime( 3934): at
android.view.View$PerformClick.run(View.java:17340)
E/AndroidRuntime( 3934): at
android.os.Handler.handleCallback(Handler.java:725)
E/AndroidRuntime( 3934): at
android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 3934): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 3934): at
android.app.ActivityThread.main(ActivityThread.java:5039)
E/AndroidRuntime( 3934): at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 3934): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 3934): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
E/AndroidRuntime( 3934): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
E/AndroidRuntime( 3934): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 2716): Force finishing activity
com.example.biometricclient/.BioClient
In between this i have Manager class and AIDL file in
framework/base/core/java/android/os to access API from MyService to App
layer.
Is I am following right way ? If no how to solve this problem.
--
--
unsubscribe: [email protected]
website: http://groups.google.com/group/android-porting
---
You received this message because you are subscribed to the Google Groups
"android-porting" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.