某些设备中的Android通知问题

某些设备中的Android通知问题,android,push-notification,google-cloud-messaging,android-notifications,Android,Push Notification,Google Cloud Messaging,Android Notifications,我是android新手。在我的一个应用程序中,我正在使用GCM服务。它在某些设备上运行良好。但当收到通知时,应用程序会在某些设备上崩溃 下面是我的代码 private static void generateNotification(Context context, String message) { long when = System.currentTimeMillis(); NotificationManager notificationManager = (Notificati

我是android新手。在我的一个应用程序中,我正在使用GCM服务。它在某些设备上运行良好。但当收到通知时,应用程序会在某些设备上崩溃

下面是我的代码

private static void generateNotification(Context context, String message) {

long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager)
            context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher, message, when);
    String title = "Application";
    Intent notificationIntent = new Intent(context, MainActivity.class);
    notificationIntent.putExtra("message", message);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
            Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent =
            PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notification.defaults|= Notification.DEFAULT_LIGHTS;
    notification.defaults|= Notification.DEFAULT_VIBRATE;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notificationManager.notify(0, notification); 

}
在此代码中将某些行显示为删除,如
new Notification

谁能告诉我这个问题吗

通过谷歌搜索,我发现这些功能在新版本中被贬低了。那么我可以继续使用新的版本代码吗

然后我的问题是,如果我为新API编写代码,那么这个应用程序是否可以兼容旧版本?当前我的
minSdkVersion=8和targetSdkVersion=16

提前谢谢
请帮助我

您不需要更改MinSDK版本和TargetSDK版本。您只需要将最新的“android-support-v4.jar”添加到您的libs文件夹中。然后使用“NotificationCompat.Builder”类显示通知。因为这是通知的新版本