Coder Social home page Coder Social logo

Comments (2)

digitGrove avatar digitGrove commented on July 18, 2024 2

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));
}

from pugnotification.

Zulqurnain avatar Zulqurnain commented on July 18, 2024

So it works ?

from pugnotification.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.