我正在尝试在我的应用程序中使用 NotificationCompat.Builder 类。以下代码在 ICS 手机上运行得非常好,但在 Gingerbread 上却不行。据我了解,支持库是否允许从 API 级别 4 低的手机访问 Builder?我在做一些根本错误的事情吗?
public class MainActivity extends Activity implements OnClickListener {
NotificationCompat.Builder builder;
NotificationManager nm;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
builder = new NotificationCompat.Builder(this);
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
builder.setContentTitle("Test Notification")
.setContentText("This is just a test notification")
.setTicker("you have been notified")
.setSmallIcon(R.drawable.ic_stat_example)
.setWhen(System.currentTimeMillis());
findViewById(R.id.btn_notify).setOnClickListener(this);
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(arg0.getId() == R.id.btn_notify){
nm.notify(1, builder.build());
}
}
}