通知Android对象错误

时间:2014-11-20 23:45:23

标签: android android-intent android-activity

所以我正在阅读Android网站上的Android Notification api,并将其作为演示文稿复制到Code中

我有错误

mNotificationManager.notify(mId,mBuilder.build());

Object中的Notify()无法应用于(int,android.app.Notification)

当我去Object.java Notify()

public final native void notify();

/**
 * Causes all threads which are waiting on this object's monitor (by means
 * of calling one of the {@code wait()} methods) to be woken up. The threads
 * will not run immediately. The thread that called {@code notify()} has to
 * release the object's monitor first. Also, the threads still have to
 * compete against other threads that try to synchronize on the same object.
 *
 * <p>This method can only be invoked by a thread which owns this object's
 * monitor. A thread becomes owner of an object's monitor
 * <ul>
 * <li>by executing a synchronized method of that object;</li>
 * <li>by executing the body of a {@code synchronized} statement that
 * synchronizes on the object;</li>
 * <li>by executing a synchronized static method if the object is of type
 * {@code Class}.</li>
 * </ul>
 *
 * @throws IllegalMonitorStateException
 *             if the thread calling this method is not the owner of this
 *             object's monitor.
 * @see #notify
 * @see #wait()
 * @see #wait(long)
 * @see #wait(long,int)
 * @see java.lang.Thread
 */

以下是Android Notification API中的代码。

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.widget.Toast;

   private void sendNotification() {
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                      .setSmallIcon(R.drawable.notification)
                        .setContentTitle("Notification")
                        .setContentText("My First Notification Bar!");
// Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(this, notificationV.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(notificationV.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.

        mNotificationManager.notify(mId, mBuilder.build());

    }

这是代码的图像它似乎在寻找Int Notification和String 但是一旦我输入它们然后显示错误

http://i.stack.imgur.com/JZ1hy.jpg

1 个答案:

答案 0 :(得分:0)

检查您如何定义mNotificationManager。看起来好像你应该Object确定它应该是NotificationManager.notify(int, Notification)方法来自NotificationManager