NativeScript / sample-android-background-services

Using Android Background Services in NativeScript
63 stars 10 forks source link

No "I" field "IMPORTANCE_LOW" in class #28

Closed JorgeHawkins closed 6 years ago

JorgeHawkins commented 6 years ago

While trying to run the demo in my 5.1.1 phone, I managed to get this error:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: com.tns.NativeScriptException: 
Calling js method onStartJob failed

Error: java.lang.NoSuchFieldError: no "I" field "IMPORTANCE_LOW" in class "Landroid/app/NotificationManager;" or its superclasses
com.tns.Runtime.callJSMethodNative(Native Method)
com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
com.tns.Runtime.callJSMethod(Runtime.java:957)
com.tns.Runtime.callJSMethod(Runtime.java:941)
com.tns.Runtime.callJSMethod(Runtime.java:933)
com.tns.notifications.MyJobService.onStartJob(MyJobService.java:13)
android.app.job.JobService$JobHandler.handleMessage(JobService.java:126)
android.os.Handler.dispatchMessage(Handler.java:102)
android.os.Looper.loop(Looper.java:135)
android.app.ActivityThread.main(ActivityThread.java:5343)
java.lang.reflect.Method.invoke(Native Method)
java.lang.reflect.Method.invoke(Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
File: "file:///data/data/org.nativescript.bgservice/files/app/notifications/MyJobService.js, line: 28, column: 58

StackTrace: 
Frame: function:'onStartJob', file:'file:///data/data/org.nativescript.bgservice/files/app/notifications/MyJobService.js', line: 28, column: 59

at android.app.job.JobService$JobHandler.handleMessage(JobService.java:130)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Caused by: com.tns.NativeScriptException: 
Calling js method on...
des-esseintes commented 6 years ago

same

manojdcoder commented 6 years ago

The error log has everything you need, IMPORTANCE_LOW is available only from API level 24. So I assume this demo works on only Android 7.x and above.

But still the idea of creating a background service is same for any version. What you write inside depends on your business requirements.

NickIliev commented 6 years ago

@des-esseintes @JorgeHawkins @manojdcoder the current implementation is using NotificationChannel and will work only on API 26+ (Android 8 and above). Added in the README

vikasacharya16 commented 5 years ago

i updated nativescirpt to latest(5.1) Then downloaded project "sample-android-background-services" from github. on click of start notification schedule button was giving this error below. i have nativescript-android-utils installed. can anyone tell me how to solve this ...!

JS: Job Scheduled: 1

JS: Job execution ... System.err: java.lang.RuntimeException: com.tns.NativeScriptException: System.err: Calling js method onStartJob failed System.err: Error: java.lang.NoSuchFieldError: no "I" field "IMPORTANCE_LOW" in class "Landroid/app/NotificationManager;" or its superclasses System.err: com.tns.Runtime.callJSMethodNative(Native Method) System.err: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101) System.err: com.tns.Runtime.callJSMethodImpl(Runtime.java:983) System.err: com.tns.Runtime.callJSMethod(Runtime.java:970) System.err: com.tns.Runtime.callJSMethod(Runtime.java:954) System.err: com.tns.Runtime.callJSMethod(Runtime.java:946) System.err: com.tns.notifications.MyJobService.onStartJob(MyJobService.java:18) System.err: android.app.job.JobService$JobHandler.handleMessage(JobService.java:126) System.err: android.os.Handler.dispatchMessage(Handler.java:102) System.err: android.os.Looper.loop(Looper.java:157) System.err: android.app.ActivityThread.main(ActivityThread.java:5601) System.err: java.lang.reflect.Method.invoke(Native Method) System.err: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774) System.err: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652) System.err: File: "file:///data/data/org.nativescript.bgservice/files/app/notifications/MyJobService.js, line: 28, column: 59 System.err: StackTrace: System.err: Frame: function:'onStartJob', file:'file:///data/data/org.nativescript.bgservice/files/app/notifications/MyJobService.js', line: 28, column: 60 System.err: at android.app.job.JobService$JobHandler.handleMessage(JobService.java:130) System.err: at android.os.Handler.dispatchMessage(Handler.java:102) System.err: at android.os.Looper.loop(Looper.java:157) System.err: at android.app.ActivityThread.main(ActivityThread.java:5601) System.err: at java.lang.reflect.Method.invoke(Native Method) System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774) System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652) System.err: Caused by: com.tns.NativeScriptException: System.err: Calling js method onStartJob failed System.err: Error: java.lang.NoSuchFieldError: no "I" field "IMPORTANCE_LOW" in class "Landroid/app/NotificationManager;" or its superclasses System.err: com.tns.Runtime.callJSMethodNative(Native Method) System.err: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101) System.err: com.tns.Runtime.callJSMethodImpl(Runtime.java:983) System.err: com.tns.Runtime.callJSMethod(Runtime.java:970) System.err: com.tns.Runtime.callJSMethod(Runtime.java:954) System.err: com.tns.Runtime.callJSMethod(Runtime.java:946) System.err: com.tns.notifications.MyJobService.onStartJob(MyJobService.java:18) System.err: android.app.job.JobService$JobHandler.handleMessage(JobService.java:126) System.err: android.os.Handler.dispatchMessage(Handler.java:102) System.err: android.os.Looper.loop(Looper.java:157) System.err: android.app.ActivityThread.main(ActivityThread.java:5601) System.err: java.lang.reflect.Method.invoke(Native Method) System.err: com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:774) System.err: com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652) System.err: File: "file:///data/data/org.nativescript.bgservice/files/app/notifications/MyJobService.js, line: 28, column: 59 System.err: StackTrace: System.err: Frame: function:'onStartJob', file:'file:///data/data/org.nativescript.bgservice/files/app/notifications/MyJobService.js', line: 28, column: 60 System.err: at com.tns.Runtime.callJSMethodNative(Native Method) System.err: at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101) System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:983) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:970) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:954) System.err: at com.tns.Runtime.callJSMethod(Runtime.java:946) System.err: at com.tns.notifications.MyJobService.onStartJob(MyJobService.java:18) System.err: at android.app.job.JobService$JobHandler.handleMessage(JobService.java:126) System.err: ... 6 more System.err: Caused by: java.lang.NoSuchFieldError: no "I" field "IMPORTANCE_LOW" in class "Landroid/app/NotificationManager;" or its superclasses System.err: ... 14 more