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 oreo support(let us know if it's impossible) #83

Open
pourya0111 opened this issue Dec 19, 2017 · 2 comments
Open

android oreo support(let us know if it's impossible) #83

pourya0111 opened this issue Dec 19, 2017 · 2 comments

Comments

@pourya0111
Copy link

No description provided.

@digitGrove
Copy link

I have a solution

1.) Add NotificationUtils.java

package br.com.goncalves.pugnotification.notification;

/**

  • Created by EZHIL on 1/11/2018.
    */

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Color;
import android.os.Build;

public class NotificationUtils extends ContextWrapper {

private NotificationManager mManager;
public static final String CHANNEL_ID = "YOUR_CHANNEL_ID";
public static final String CHANNEL_NAME = "YOUR_CHANNEL_NAME";

public NotificationUtils(Context base) {
    super(base);
    createChannels();
}

public void createChannels() {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            // create android channel
            NotificationChannel androidChannel = new NotificationChannel(CHANNEL_ID,
                    CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
            // Sets whether notifications posted to this channel should display notification lights
            androidChannel.enableLights(true);
            // Sets whether notification posted to this channel should vibrate.
            androidChannel.enableVibration(true);
            // Sets the notification light color for notifications posted to this channel
            androidChannel.setLightColor(Color.BLUE);
            // Sets whether notifications posted to this channel appear on the lockscreen or not
            androidChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
            getManager().createNotificationChannel(androidChannel);
        }
    }catch (Exception e){
        e.printStackTrace();
    }
}

private NotificationManager getManager() {
    if (mManager == null) {
        mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    }
    return mManager;
}

}

2.) make this change in Load.java

public Load() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
try {
NotificationUtils notificationUtils = new NotificationUtils(PugNotification.mSingleton.mContext);
builder = new NotificationCompat.Builder(PugNotification.mSingleton.mContext, NotificationUtils.CHANNEL_ID);
}catch (Exception e){
e.printStackTrace();
}
}else {
builder = new NotificationCompat.Builder(PugNotification.mSingleton.mContext);
}
builder.setContentIntent(PendingIntent.getBroadcast(PugNotification.mSingleton.mContext, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT));
}

@Zulqurnain
Copy link

So it works ?

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

3 participants