首先,我是初学者,如果我错过了某些东西或者没有轻易获得某些东西,请耐心等待。我正在研究这个项目所使用的函数在API 23中已被弃用我完全清楚这一点,不能回去所以我必须只修复当前的代码。下面只有一半代码,问题是如果我正在尝试更改setLatestEventInfo,其他一切都停止工作。如果有人帮助我的话,我真的很想知道要改变什么以及如何感激我真的很感激。从过去的两天开始疯狂。谢谢!
private void EmergencyNotification(Context context, String message) {
int icon = R.drawable.pus_notification;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = "Emergency Alert";
notification.setLatestEventInfo(context, title, message, null);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_SOUND;
long[] vibrate = { 0, 100, 200, 300 };
notification.vibrate = vibrate;
notificationManager.notify(0, notification);
Object sbservice = getSystemService("statusbar");
Class<?> statusbarManager = null;
try {
statusbarManager = Class.forName("android.app.StatusBarManager");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Method showsb = null;
if (Build.VERSION.SDK_INT >= 17) {
try {
showsb = statusbarManager.getMethod("expandNotificationsPanel");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
try {
showsb = statusbarManager.getMethod("expand");
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
showsb.invoke(sbservice);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (NullPointerException e) {
} catch (Exception e) {
// TODO: handle exception
}