2014-11-20 55 views
1

所以我正在读在Android网站的Android通知API和复制的代码,他们有一个演示 ,但我对通知Android的对象错误

mNotificationManager.notify(MID,mBuilder.build错误());

通知()的对象不能appled,与(int,android.app.Notification)

当我去Object.java通知()

公众最终无效本地通知();

/** 
* 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()); 

    } 

这里是代码的图像好像看向诠释通知和字符串 但一旦我在其中输入他们然后才显示出来的错误

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

回答

0

检查你怎么有定义为mNotificationManager。看起来好像您已将其定义为Object,但实际上应该是NotificationManager.notify(int, Notification)方法是从NotificationManager

+0

我做了一个编辑到上面的文本,我放在我的进口。我不知道如果问题在于导入android.support.v4.app.NotificationCompat; – Dave 2014-11-21 09:29:14

+0

我刚刚运行应用程序,出现错误,现在通知似乎正在传递。奇怪的.. – Dave 2014-11-21 10:40:44