【发布时间】:2013-08-30 07:08:35
【问题描述】:
我想创建一个示例项目以在单击按钮时显示通知,然后当用户选择它时在我的应用程序中打开该活动或打开一个选择该活动的 url。我做了一些事情,但我无法完成功能。
首先我在使用这个时遇到了错误:@SuppressLint("NewApi")
如果我不使用它,我会在这里收到错误
Notification noti = new Notification.Builder(this)
活动代码
public class NotificationExample extends Activity implements OnClickListener{
private Button b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification_example);
b=(Button)findViewById(R.id.button1);
b.setOnClickListener(this);
}
@SuppressLint("NewApi")
@Override
public void onClick(View v) {
Intent intent = new Intent();
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification noti = new Notification.Builder(this)
.setTicker("Ticker Title")
.setContentTitle("Content Title")
.setContentText("Notification content.")
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(pIntent).getNotification();
noti.flags=Notification.FLAG_AUTO_CANCEL;
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, noti);
}
}
为什么我必须使用这个:
`@SuppressLint("NewApi")`
在我的代码中? 我没有收到通知声音。请建议我必须对代码进行哪些更改。
【问题讨论】:
-
为什么我必须在我的代码中使用这个@SuppressLint("NewApi")。它没有给我通知声音
-
@SuppressLint("NewApi") 是 Android Lint 工具使用的注解。
-
以及为什么我没有收到通知声音
标签: android android-intent android-notifications