我正在尝试运行以下内容,该内容来自互联网教程:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// Prepare intent which is triggered if the
// notification is selected
Intent homeIntent = new Intent(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_HOME);
//Intent intent = new Intent(this, ReceiveAndGoHome.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, homeIntent, 0);
// Build notification
// Actions are just fake
Notification noti = new NotificationCompat.Builder(this)
.setContentTitle("Fraz Go Home!!!")
.setContentTitle("Fraz Go Home!!!")
.setContentText("Fraz Go Home!!!")
.setContentIntent(pIntent)
.addAction(R.drawable.ic_launcher, "Call", pIntent)
.addAction(R.drawable.ic_launcher, "More", pIntent)
.addAction(R.drawable.ic_launcher, "And more", pIntent).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(25, noti);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
当我在 froyo AVD 中运行上述内容时,我根本没有看到通知出现 - 我是否遗漏了一些明显的东西?