3

我将我的应用程序添加到谷歌播放,但我在通知 bulider 上遇到了一些崩溃,这是崩溃消息

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 中遇到错误和崩溃

4

2 回答 2

2

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

于 2014-05-13T14:54:14.217 回答
0

这是因为支持包问题,试试这个,它对我 有用 https://stackoverflow.com/a/16523845/2534313

于 2013-11-22T06:48:37.773 回答