Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 8.1 or 9.0 Error when clicking on connect #19

Open
hamzology opened this issue May 28, 2019 · 1 comment
Open

Android 8.1 or 9.0 Error when clicking on connect #19

hamzology opened this issue May 28, 2019 · 1 comment

Comments

@hamzology
Copy link

When I have compiled an apk and tried to run on android 8.0 it was working fine but when I installed the same apk in my android 9.0 and then click on connect vpn button it is crashing and giving the below error:

Fatal Exception: 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 tick defaults=0x0 flags=0x14a color=0x00000000 category=service actions=2 vis=PRIVATE)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2082)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:7539)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)

@i-build-web-apps
Copy link

i-build-web-apps commented May 31, 2019

In OpenVPNService.java, add the following method:

@RequiresApi(api = Build.VERSION_CODES.O)
private String createNotificationChannel(String channelId, String channelName){
    NotificationChannel chan = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
    chan.setLightColor(Color.BLUE) ;
    chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
    NotificationManager service = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    service.createNotificationChannel(chan);
    return channelId ;
}

Then replace:

    android.app.Notification.Builder nbuilder = new Notification.Builder(this);

with:

    String channelID = "" ;
    android.app.Notification.Builder nbuilder ;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        channelID = createNotificationChannel("my_service", "My Background Service") ;
        nbuilder = new Notification.Builder(this, channelID);
    }
    else
        nbuilder = new Notification.Builder(this);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants