如何在Android api级别19上显示通知
我试图使用此代码在单击按钮时发送通知,但代码中出现错误,显示错误调用需要API级别11(当前最小值为8):android.app.Notification.Builder#setContentIntent我已将项目Api级别设置为19请帮助我哪里做错了请建议我解决方案target=android-19项目属性,同时我必须编写以下代码:如何在Android api级别19上显示通知,android,Android,我试图使用此代码在单击按钮时发送通知,但代码中出现错误,显示错误调用需要API级别11(当前最小值为8):android.app.Notification.Builder#setContentIntent我已将项目Api级别设置为19请帮助我哪里做错了请建议我解决方案target=android-19项目属性,同时我必须编写以下代码: public void onClick(View v) { Intent notificationIntent = new Intent(this
public void onClick(View v) {
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 1,
notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationManager nm = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Resources res = this.getResources();
Notification.Builder builder = new Notification.Builder(this);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(
BitmapFactory.decodeResource(res,
R.drawable.ic_launcher)).setTicker("helllo")
.setWhen(System.currentTimeMillis()).setAutoCancel(true)
.setContentTitle("Messge").setContentText("Messge22");
Notification n = builder.build();
nm.notify(5, n);
}
如果您的应用程序支持与API级别4相同的
Android版本,您可以改为使用NotificationCompat.Builder
,该版本可在中找到
Notification.Builder-该类是在Android 3.0蜂巢[API 11]
中添加的。因此,如果您需要支持较旧的SDK,则需要使用NotificationCompact
NotificationCompat.Builder–该类位于版本4支持库中(兼容Android 1.6及更高版本)
有关更多信息,请访问清单文件OK Suppoe中的设置android:minSdkVersion=“11”,如果我们将设置min-sdk android:minSdkVersion=“11”,它将适用于所有未使用的设备NotificationCompact
对于较旧的android版本支持,我将在哪里使用请编辑我的代码,因为android:minSdkVersion=“11”工作很好,但我希望它在所有,所以请编辑我的代码不,我不是…只是去做你自己。。。。我想要这个请帮帮我
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />