How to migrate from Notificationmanager to Notificationcompat in API 23

Asked

Viewed 57 times

0

according to the title, I am that problem. I am novice at this and am not managing to migrate to API 23 (Notificationcompat). Could you help me?

Follows my code:

    @SuppressWarnings("deprecation")
    @Override
    public void onStart(Intent intent, int startId) {
        Log.d(TAG, "onStart");
        mp.start();
        // Set the isPlaying preference to true
        editor.putBoolean("isPlaying", true);
        editor.commit();

        Context context = getApplicationContext();
        String notifTitle = context.getResources().getString(R.string.app_name);
        String notifMessage = context.getResources().getString(R.string.now_playing);

        n.icon = R.mipmap.ic_launcher;
        n.tickerText = notifMessage;
        n.flags = Notification.FLAG_NO_CLEAR;
        n.when = System.currentTimeMillis();

        Intent nIntent = new Intent(context, MainActivity.class);
        PendingIntent pIntent = PendingIntent.getActivity(context, 0, nIntent, 0);

        n.NotificationManager(context, notifTitle, notifMessage, pIntent);
        // Change 5315 to some nother number
        notificationManager.notify(notifId, n);
    }

    @Override
    public void onDestroy() {
        Log.d(TAG, "onDestroy");
        mp.stop();
        mp.release();
        mp = null;
        editor.putBoolean("isPlaying", false);
        editor.commit();
        notificationManager.cancel(notifId);
    }

}
  • what error are you having? have a Log, something to facilitate understanding?

  • Is returning error on line: n.Notificationmanager(context, notifTitle, notifMessage, pIntent);

1 answer

1


Change

 n.NotificationManager(context, notifTitle, notifMessage, pIntent);

for :

   n.setContentIntent(pIntent);

to pass the PendingIntent for your Notification.Builder

  • Persist further: Error:(63, 10) error: cannot find Symbol method setContentIntent(Pendingintent)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.