connectivity-samples
                                
                                
                                
                                    connectivity-samples copied to clipboard
                            
                            
                            
                        Crash on broadcast device switched
I am running Android Oreo 8.1 in google pixel.
02-27 10:28:50.460 10260-10260/com.example.android.bluetoothadvertisements E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.android.bluetoothadvertisements, PID: 10260 android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Fixed changed the goForeground method by:
private NotificationManager manager;
private NotificationManager getManager() {
        if (manager == null) {
            manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        }
        return manager;
}
private void goForeground() {
        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);
        Notification n;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
            NotificationChannel chan1 = new NotificationChannel("default",
                    "default", NotificationManager.IMPORTANCE_DEFAULT);
            chan1.setLightColor(Color.GREEN);
            chan1.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
            getManager().createNotificationChannel(chan1);
            n = new Notification.Builder(this, chan1.getId())
                    .setContentTitle("Advertising device via Bluetooth")
                    .setContentText("This device is discoverable to others nearby.")
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentIntent(pendingIntent)
                    .build();
        } else {
            n = new Notification.Builder(this)
                    .setContentTitle("Advertising device via Bluetooth")
                    .setContentText("This device is discoverable to others nearby.")
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentIntent(pendingIntent)
                    .build();
        }
        startForeground(FOREGROUND_NOTIFICATION_ID, n);
    }
                                    
                                    
                                    
                                
Thanks for the answer, but can you post your getManager()?
Sorry, my bad. I have updated the code.
Thank you!
I'm facing issue with android 8.1.0 .. can you please tell me how to fix the issue.
07-17 19:54:58.133 1930-2430/system_process E/InputDispatcher: channel 'f9b795c com.kuku.namaste/cat.ereza.customactivityoncrash.activity.DefaultErrorActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 07-17 19:54:58.294 1930-1965/system_process E/zygote: Error encountered killing process cgroup uid 99002 pid 6946: No such file or directory 07-17 19:54:58.309 1930-1966/system_process E/KernelCpuSpeedReader: Failed to read cpu-freq: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state (No such file or directory) 07-17 19:54:58.523 1930-1972/system_process E/NetdConnector: NDC event {613 IfaceClass active 1 1581240096160 10014} took too long: 3080ms 07-17 19:55:00.271 1930-1972/system_process E/NetdConnector: NDC event {613 IfaceClass active 0 1581240204830 0} processed too late: 3105ms 07-17 19:55:00.273 1930-1972/system_process E/NetdConnector: NDC event {613 IfaceClass active 0 1581240204830 0} took too long: 1723ms 07-17 19:55:00.533 1930-1962/system_process E/memtrack: Couldn't load memtrack module 07-17 19:55:05.480 1930-1966/system_process E/BatteryExternalStatsWorker: modem info is invalid: ModemActivityInfo{ mTimestamp=0 mSleepTimeMs=0 mIdleTimeMs=0 mTxTimeMs[]=[0, 0, 0, 0, 0] mRxTimeMs=0 mEnergyUsed=0} 07-17 19:55:10.404 1930-1962/system_process E/memtrack: Couldn't load memtrack module 07-17 19:55:14.040 1930-1962/system_process E/memtrack: Couldn't load memtrack module 07-17 19:55:16.825 1416-1502/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 07-17 19:55:17.084 7068-7068/? E//system/bin/webview_zygote32: Failed to make and chown /acct/uid_99003: Permission denied 07-17 19:55:17.084 7068-7068/? E/Zygote: createProcessGroup(99003, 0) failed: Permission denied 07-17 19:55:17.326 7091-7091/? E/asset: setgid: Operation not permitted 07-17 19:55:17.487 6996-6996/com.kuku.namaste E/@@@@@@@@@@@@@: false 07-17 19:55:17.758 1416-1464/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 07-17 19:55:25.490 1930-1966/system_process E/BatteryExternalStatsWorker: modem info is invalid: ModemActivityInfo{ mTimestamp=0 mSleepTimeMs=0 mIdleTimeMs=0 mTxTimeMs[]=[0, 0, 0, 0, 0] mRxTimeMs=0 mEnergyUsed=0} 07-17 19:55:30.794 1930-1962/system_process E/memtrack: Couldn't load memtrack module 07-17 19:55:30.815 1930-1962/system_process E/memtrack: Couldn't load memtrack module 07-17 19:55:37.763 6996-7030/com.kuku.namaste E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE 07-17 19:55:38.677 6996-6996/com.kuku.namaste E/AndroidRuntime: FATAL EXCEPTION: main Process: com.kuku.namaste, PID: 6996 android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 07-17 19:55:40.331 6996-6996/com.kuku.namaste E/CustomActivityOnCrash: App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 07-17 19:55:41.153 1930-1965/system_process E/zygote: Error encountered killing process cgroup uid 99003 pid 7068: No such file or directory 07-17 19:55:41.166 1930-1966/system_process E/KernelCpuSpeedReader: Failed to read cpu-freq: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state (No such file or directory) 07-17 19:55:41.811 7118-7118/? E/CustomActivityOnCrash: The previous app process crashed. This is the stack trace of the crash: android.app.RemoteServiceException: Bad notification for startForeground: java.lang.RuntimeException: invalid channel for service notification: Notification(channel=null pri=0 contentView=null vibrate=null sound=null defaults=0x0 flags=0x40 color=0x00000000 vis=PRIVATE) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1768) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) 07-17 19:55:42.433 1416-2437/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 07-17 19:55:42.643 7161-7161/? E//system/bin/webview_zygote32: Failed to make and chown /acct/uid_99004: Permission denied 07-17 19:55:42.643 7161-7161/? E/Zygote: createProcessGroup(99004, 0) failed: Permission denied 07-17 19:55:42.760 7161-7161/? E//system/bin/webview_zygote32: Failed to send JDWP packet APNM to debugger (-1 of 101): Broken pipe 07-17 19:55:42.793 7176-7176/? E/asset: setgid: Operation not permitted 07-17 19:55:43.943 7161-7168/? E//system/bin/webview_zygote32: Failed sending reply to debugger: Broken pipe 07-17 19:55:43.994 1416-1730/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property 07-17 19:55:44.020 1347-1347/? E/hw-IPCThreadState: attemptIncStrongHandle(23): Not supported 07-17 19:55:44.021 1347-1347/? E/hw-IPCThreadState: attemptIncStrongHandle(23): Not supported
Thanks @agustinsivoplas for the fix! Have you considering issuing a pull request?
Thanks @agustinsivoplas for the fix! Have you considering issuing a pull request?
I just made mine pr for this issue, check here if you like: https://github.com/googlesamples/android-BluetoothAdvertisements/pull/16
Same issue after changing goForeground method also.please help me to resolve this issue