Issue with NotificationCompact.Builder and ActionBarSherlock

谁说胖子不能爱 提交于 2020-01-01 08:55:23

问题


In the following code, Eclipse found an error:

The method build() is undefined for the type NotificationCompat.Builder

Everything worked fine before adding the ActionBarSherlock (following this tutorial).

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TaskStackBuilder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

public class NotificationActivity extends BroadcastReceiver {

    NotificationManager nm;

    @Override
    public void onReceive(Context context, Intent intent) {
        nm = (NotificationManager) context
                .getSystemService(Context.NOTIFICATION_SERVICE);
        int notifyID = 1;
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                context)
                .setSmallIcon(R.drawable.zcicon)
                .setAutoCancel(true)
                .setDefaults(
                        Notification.DEFAULT_SOUND
                                | Notification.DEFAULT_LIGHTS)
                .setTicker("mytitle").setContentTitle("mycontent")
                .setContentText("text, text");
        Intent resultIntent = new Intent(context, CalcareReader.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(MyActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(resultPendingIntent);

        nm.notify(notifyID, mBuilder.build()); // error here
    }
}

回答1:


build() was added in a newer edition of the Android Support package. Depending on how you obtained and set up ActionBarSherlock, you may be using an older edition of the Android Support package. Make sure that you have the latest one downloaded in your SDK Manager, then use that android-support-v4.jar in both the ActionBarSherlock project and your main application project.




回答2:


build() is from an older version of android-support-v4.jar

[ If using ActionBar Sherlock ]

1 Update the Android Support Library from SDK

2 Copy paste this to your lib/ folder, or update the reference at the Path

3 Do the same with the sherlockactionbar project. Be careful, if you have an android-support2-v4.jar, delete it and add only the android-support-v4.jar

4 Clean



来源:https://stackoverflow.com/questions/15361324/issue-with-notificationcompact-builder-and-actionbarsherlock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!