且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NotificationCompat2错误:java.lang.IllegalArgumentException异常

更新时间:2023-01-24 12:45:03

我不知道是什么错误,但是这片code作品

I don't know what the error was but this piece of code works

private static final int UPDATE_PROGRESS = 123654789;
private NotificationManager notifManager;
private Context mContext;
private NotificationCompat2.Builder mNotification;
private String content = "";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = MainActivity.this;
    notifManager = (NotificationManager)
                    mContext.getSystemService(mContext.NOTIFICATION_SERVICE);
    mNotification = new NotificationCompat2.Builder(mContext)
            .setSmallIcon(android.R.drawable.sym_def_app_icon)
            .setTicker("Launch download")
            .setContentTitle("Downloader")
            .setContentText(content)
            .setContentIntent(getPendingIntent());
    notifManager.notify(UPDATE_PROGRESS, mNotification.build() );
}

private PendingIntent getPendingIntent() {
    Intent i = new Intent(mContext, MainActivity.class);
    i.setFlags(FLAG_ACTIVITY_CLEAR_TOP);
    return PendingIntent.getActivity(mContext, 0, i, 0);
}