Cannot Resolve Method setLatestEventInfo

过时代码

    notification.setLatestEventInfo(context, appName, contentText, contentIntent);

新代码

//https://stackoverflow.com/questions/32345768/cannot-resolve-method-setlatesteventinfo
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
    try {
    //采用反射调用notification.setLatestEventInfo(context, appName, contentText, //contentIntent);
                    Method deprecatedMethod = notification.getClass().
                    getMethod("setLatestEventInfo", Context.class, CharSequence.class,
                     CharSequence.class, PendingIntent.class);
                    deprecatedMethod.invoke(notification, context, appName, 
                    contentText, contentIntent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
}else{
    //采用Notification.Builder来构建
}

你可能感兴趣的:(Android)