【发布时间】:2015-10-24 21:16:48
【问题描述】:
我正在创建一个模拟推送通知应用。
它接受用户的输入并在设备上显示本地推送通知。
据我所知setLatestEventInfo 方法在新的API (23+) 级别中已停用。
我想知道代码的可能补丁是什么。
下面是代码:
public class MainActivity extends ActionBarActivity {
EditText ed1,ed2,ed3;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.editText);
ed2=(EditText)findViewById(R.id.editText2);
ed3=(EditText)findViewById(R.id.editText3);
Button b1=(Button)findViewById(R.id.button);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String tittle=ed1.getText().toString().trim();
String subject=ed2.getText().toString().trim();
String body=ed3.getText().toString().trim();
NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notify=new Notification(R.drawable.icon,tittle,System.currentTimeMillis());
PendingIntent pending= PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0);
notify.setLatestEventInfo(getApplicationContext(),subject,body,pending); //cannot resolve 'setLatestEventInfo' method
notif.notify(0, notify);
}
});
}
谢谢你:)
【问题讨论】:
-
为什么需要它? AFAIK,
setLatestEventInfo()能做的一切都由NotificationCompat.Builder处理。 -
是的,正是...谢谢...但是我如何在我的代码中实现它?
-
先生理解起来越来越复杂了:(
标签: java android notifications push-notification