I am trying to create a simple notification in android. The purpose is to show a small icon on top of the phone screen when something is happening. Then I can tap on the notification which will either start the app or brings it in the foreground.
For just testing purposes I am following this hard-to-understand-and-not-simple example and also found this entry for the first error I get.
Anyway here is the code:
Notification mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon1) .setContentTitle("My notification") .setContentText("Hello World!"); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( 0, PendingIntent.FLAG_UPDATE_CURRENT ); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. int mId = 1001; mNotificationManager.notify(mId, mBuilder.build()); and here is what I am importing:
... import android.app.Notification; import android.app.NotificationManager; .... import android.support.v7.app.ActionBar; //import android.support.v4.app.NotificationCompat; import android.support.v7.app.AppCompatActivity; import android.support.v7.app.NotificationCompat; import android.support.v7.widget.Toolbar; The current error is
Error:(117, 32) error: incompatible types required: Notification found: Builder How to fix this problem?
NotificationCompat.Builderto aNotification.