In Android How to show Notification From C library
After completion of some work in Middleware C library, Need to show few notifications to Notification bar. Please suggest if any work around to show the notifications.This C library 开发者_运维问答doesnt have GUI part of it.
As Nitrex said, you would need to call the method in your Java class via JNI:
In C:
void
Java_com_example_hellojni_HelloJni_doSomeInterestingJob( JNIEnv* env,
jobject thiz )
{
jclass cls = (*env)->GetObjectClass(env, thiz);
jmethodID mid = (*env)->GetMethodID(env, cls, "callback", "()V");
if (mid == 0)
return;
(*env)->CallVoidMethod(env, thiz, mid);
}
In your "HelloJni" (pls. find a better name ;-)) class, you can then call:
public void callback() {
Log.d(TAG, "...");
// Start notifications now.
}
Your going to have to call java methods from your C code using Java Native Interface code (JNI). Read about JNI online for how you can do this. Then in java, you can add the notifications to the notification bar. If you can't figure out calling java methods, comment here or post a new question on it.
精彩评论