Я пытаюсь сделать мое приложение создать уведомление, но этот код дает мне ошибку компиляции:Получение ошибки при попытке сделать уведомление о
public void makeRing(Context context, boolean notify)
{
if (notify)
{
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
//.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My notification")
.setContentText("Hello World!");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, 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(context);
// 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) context.getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on (first number)
mNotificationManager.notify(5954, mBuilder.build());
}
Это код взят прямо с сайта для разработчиков Android. Ошибки находятся в строке, которая говорит «TaskStackBuilder stackBuilder = TaskStackBuilder.create (context);», где create подчеркнуто, и он говорит: «метод create (Context) не определен для типа TaskStackBuilder».
Кроме того, в последней строке build() подчеркнуто, и он говорит: «Метод build() не определен для типа NotificationCompat.Builder.
Как это решить?
Я просто загружаю последнюю версию? – AggieDev
Это должно сработать. – Eran
Я так и сказал, что мой текущий Rev. для «Android Support Library» в Android SDK Manager равен 10, но у него все еще есть эта ошибка. – AggieDev