Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not getting the notification from NotificationCompat.Builder

i want to generate a notification bar showing the progress via builder method but i dont know where i am going wrong.if anyone who can tell me where i am wrong and help me i will be thankful.....

public class DownloadReceiver extends ResultReceiver{
    private final static String TAG = "DownloadReceiver"; 
    public Context context;
    public DownloadReceiver(Handler handler,Context context) {
        super(handler);
        this.context = context;
        Log.d(TAG,handler.getLooper().getThread().getName());
    }

    @Override
    protected void onReceiveResult(int resultCode, Bundle resultData) {
        super.onReceiveResult(resultCode, resultData);
        Log.d(TAG,"in download receiver");

        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Service.NOTIFICATION_SERVICE);
        Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com"));
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notifyIntent, 0);

    if(resultCode == DownloadService.COMPLETED){
            Log.d(TAG,resultCode + "");
            Builder notificationBuilder = new NotificationCompat.Builder(context)
                                          .setProgress(100, 20, false)
                                          .addAction(R.drawable.ic_action_search, "title", pendingIntent)
                                          .setWhen(System.currentTimeMillis());
    //      notification.flags = Notification.FLAG_ONGOING_EVENT;
            //      notification.setLatestEventInfo(context, "contentTitle", "contentText", pendingIntent);
            notificationManager.notify(50, notificationBuilder.build());
        }else if(resultCode == DownloadService.ALLCOMPLETED){

        }
    }
}
like image 398
user1361425 Avatar asked Dec 21 '22 14:12

user1361425


1 Answers

I just had to deal with this just now, the solution for me was that you have to add a notification image

.setSmallIcon(R.drawable.launcher)

otherwise it won't show anything. The old notification method didn't require you to set this yourself, as it would default to the app's icon.

like image 154
CQM Avatar answered Mar 07 '23 17:03

CQM