0

我是安卓新手。在我的一个应用程序中,我正在使用 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 and targetSdkVersion=16

提前谢谢请帮帮我

4

1 回答 1

1

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

于 2013-08-08T08:15:23.473 回答