android – 使用NotificationCompact.Builder和ActionBarSherlock发行

前端之家收集整理的这篇文章主要介绍了android – 使用NotificationCompact.Builder和ActionBarSherlock发行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在下面的代码中,Eclipse发现了一个错误: @H_301_2@The method build() is undefined for the type NotificationCompat.Builder

添加ActionBarSherlock之前,一切顺利.

@H_301_2@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 } }

解决方法

build()已添加到新版本的Android支持包中.根据您获取和设置ActionBarSherlock的方式,您可能会使用旧版Android支持包.确保您在SDK Manager中下载了最新版本,然后在ActionBarSherlock项目和主应用程序项目中使用该android-support-v4.jar.

猜你在找的Android相关文章