-1
public void onClick(View v) {
        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 1,
                notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationManager nm = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Resources res = this.getResources();
        Notification.Builder builder = new Notification.Builder(this);

        builder.setContentIntent(contentIntent)
                .setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(
                        BitmapFactory.decodeResource(res,
                                R.drawable.ic_launcher)).setTicker("helllo")
                .setWhen(System.currentTimeMillis()).setAutoCancel(true)
                .setContentTitle("Messge").setContentText("Messge22");
        Notification n = builder.build();

        nm.notify(5, n);
    }

I am trying to use this Code for Send Notification On Button click but there is Error coming in Code it show Error Call requires API level 11 (current min is 8): android.app.Notification.Builder#setContentIntent i have set Project Api Level 19 please help me where am doing wrong please suggest me Solution target=android-19 Project Properties while I have to code for:

  <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
Cœur
  • 37,241
  • 25
  • 195
  • 267
user2794306
  • 175
  • 3
  • 5
  • 24

1 Answers1

1

If your app supports versions of Android as old as API level 4, you can instead use NotificationCompat.Builder, available in the Android Support library.

Notification.Builder - This class was added in Android 3.0 Honeycomb [API 11]. So if you need to support older SDK’s you will need to use NotificationCompact instead.

NotificationCompat.Builder – This class is in the version 4 Support Library (compatible Android 1.6 and up).

For more info go to How exactly to use Notification.Builder

Community
  • 1
  • 1
M D
  • 47,665
  • 9
  • 93
  • 114