如何创建Android通知?

如何创建Android通知?,android,android-notifications,Android,Android Notifications,我一步一步地遵循他们的教程,但我不断地遇到奇怪的错误 notifymanager没有.notify()作为方法,任何包含notifymanager的代码行都必须有括号,无论它在代码中的什么位置 我开始认为这是一个依赖问题,请帮助 活动1 import android.os.Bundle; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; imp

我一步一步地遵循他们的教程,但我不断地遇到奇怪的错误

notifymanager没有.notify()作为方法,任何包含notifymanager的代码行都必须有括号,无论它在代码中的什么位置

我开始认为这是一个依赖问题,请帮助

活动1

import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;


public class NotificationAlert extends Activity {


private static final int NOTIFY_ME_ID=1337;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.notification_alert);

    /*********** Create notification ***********/

    final NotificationManager mgr=
        (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification note=new Notification(R.drawable.stat_notify_chat,
                                                    "Android Example Status message!",
                                                    System.currentTimeMillis());

    // This pending intent will open after notification click
    PendingIntent i=PendingIntent.getActivity(this, 0,
                                            new Intent(this, NotifyMessage.class),
                                            0);

    note.setLatestEventInfo(this, "Android Example Notification Title",
                            "This is the android example notification message", i);

    //After uncomment this line you will see number of notification arrived
    //note.number=2;
    mgr.notify(NOTIFY_ME_ID, note);


}
}
活动2

 import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;

public class NotifyMessage extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView txt=new TextView(this);

        txt.setText("Activity after click on notification");
        setContentView(txt);
    }
}

如果这段代码是在3年前编写的,在它成为创建通知的最佳且唯一推荐的方法之前,这段代码可能会更正确,因为您遵循的是什么教程?我希望能有个好消息?