安卓java.lang.NoClassDefFoundError : android. app.Notification$Builder

标签 android notifications

我将我的应用程序添加到 google play,但我在通知生成器上遇到了一些崩溃, 这是崩溃信息

java.lang.NoClassDefFoundError: android.app.Notification$Builder

这是我的通知创建代码,

    public void CreateNtf(String text)
{   

    Notification notificationView;
    PendingIntent pendingIntent = PendingIntent.getActivity( MainActivity.this,0,getIntent(),Intent.FLAG_ACTIVITY_NEW_TASK);
    if(Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT <= 15){

         notificationView = new Notification.Builder(context)
        .setContentTitle(getResources().getString(R.string.app_name))
        .setContentText(text)
        //.setTicker(getResources().getString(R.string.app_name) + " " + text)
        .setWhen(System.currentTimeMillis())
        .setContentIntent(pendingIntent)
        //.setDefaults(Notification.DEFAULT_SOUND)
        .setAutoCancel(false)
        .setSmallIcon(R.drawable.ic_launcher)
        .getNotification();
    }else{
             notificationView = new Notification.Builder(context)
            .setContentTitle(getResources().getString(R.string.app_name))
            .setContentText(text)
            //.setTicker(getResources().getString(R.string.app_name) + " " + text)
            .setWhen(System.currentTimeMillis())
            .setContentIntent(pendingIntent)
            //.setDefaults(Notification.DEFAULT_SOUND)
            .setAutoCancel(false)
            .setSmallIcon(R.drawable.ic_launcher)
            .build();

    }
    notificationView.flags |= Notification.FLAG_NO_CLEAR;
    notificationView.flags |= Notification.FLAG_ONGOING_EVENT;
  notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  notificationManager.notify(1, notificationView);




}

请问我该如何解决这个问题? 我仍然在 Google Play 中遇到错误和崩溃

最佳答案

Notification.Builder低于 11 的 API 不支持。您可以使用 NotificationCompat.Builder或直接创建通知并使用 setLatestEventInfo .

关于安卓java.lang.NoClassDefFoundError : android. app.Notification$Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17671470/

相关文章:

android - Fragment.replace 不会删除一个 fragment ,而是与多个其他 fragment 一起使用

java - 在指定日期之前在 Android 中通知

ios - 是否可以在 iOS 应用程序上设置用户自定义通知?

swift - 经过一定时间后触发 Xcode 通知 (Swift 3)

android - Firefox for Android 附加组件在 Nightly 中被禁用了吗?

Android - 如何从最近的应用程序中删除 Activity ?

android - 如何从 Facebook SDK 3.0 获取好友列表

android - Nexus S 和三星 Galaxy S I9000 上的 ACTION_IMAGE_CAPTURE 方向问题

objective-c - 我可以在弹出窗口消失时触发通知吗 (iPad)

c# - 子属性更改时,FreezableCollection 不提供更改通知