Здесь вы можете найти лучшее объяснение с исходными кодами уведомлений.
Уведомление может быть реакцией на какое-то событие. Например, вы можете разработать простое приложение с одной кнопкой. При нажатии этой кнопки в строке состояния будет отображаться уведомление.
О разработке. Вам необходимо установить Android SDK, создать эмулятор устройства. Также очень полезно установить Android ADT - это расширение для Eclipse, помогающее разрабатывать приложения для Android. После этого при создании приложения оно будет автоматически установлено на эмуляторе.
Вот код, как сделать простое уведомление:
package your.package
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class AcNotificationTestMain extends Activity implements OnClickListener {
/** Called when the activity is first created. */
private static final int SEND_ID = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button mBtnSend = (Button) findViewById(R.id.button1);
mBtnSend.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
Log.v("","OnClick...");
// Create an object of Notification manager
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = android.R.drawable.sym_action_email; // icon from resources
CharSequence tickerText = "New Notification"; // ticker-text
long when = System.currentTimeMillis(); // notification time
Context context = getApplicationContext(); // application Context
CharSequence contentTitle = "My notification"; // expanded message title
CharSequence contentText = "Click me!"; // expanded message text
Intent notificationIntent = new Intent(this, AcNotificationTestMain.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
// the next two lines initialize the Notification, using the configurations above
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(SEND_ID, notification);
}
}
И файл макета:
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello"/>
<Button android:id="@+id/button1" android:text="@string/AcNotificationTest_BtnSendNotificationText" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>