Android 通知未出现在通知托盘中

Android 通知未出现在通知托盘中,android,notifications,Android,Notifications,在我的应用程序中,我有一个LocationTester服务实现LocationListener,它负责从sqlite Db检索提醒,并将它们的距离与onLocationChanged()中的当前位置进行比较方法,然后在距离小于1公里时显示信息,然后抛出与该特定提醒相关的通知 问题是,当我检查某个位置并获得成功响应时,一切都进行得很顺利,甚至土司在符合条件的地方显示,但我没有收到任何通知 位置检测仪服务: public void onLocationChanged(Location locatio

在我的应用程序中,我有一个
LocationTester服务实现LocationListener
,它负责从sqlite Db检索提醒,并将它们的距离与
onLocationChanged()中的当前位置进行比较
方法,然后在距离小于1公里时显示信息,然后抛出与该特定提醒相关的通知

问题是,当我检查某个位置并获得成功响应时,一切都进行得很顺利,甚至土司在符合条件的地方显示,但我没有收到任何通知

位置检测仪服务:

public void onLocationChanged(Location location) {
        dataSrc.open();
        ArrayList<Reminders> rems = (ArrayList<Reminders>) dataSrc.findALL();

        for(Reminders x:rems){
            Location locs = new Location("");
            locs.setLatitude(x.getLat());
            locs.setLongitude(x.getLng());

            double dis = location.distanceTo(locs);
            if(dis<=1000){
                String title = x.getTitle();
                String des = x.getDescription();
                Intent intent = new Intent(this,ActivityShowReminders.class);
                NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
                builder.setContentTitle(title);
                builder.setContentText(des);
                noteManag = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                noteManag.notify(noteId,builder.build());
                noteId += 1;
                Toast.makeText(this, title+"("+des+")", Toast.LENGTH_LONG).show();
            }
        }
public void onLocation已更改(位置){
dataSrc.open();
ArrayList rems=(ArrayList)dataSrc.findALL();
用于(提醒x:rems){
位置locs=新位置(“”);
位置设置纬度(x.getLat());
locs.setLongitude(x.getLng());
双dis=位置。距离(locs);
if(dis0){
while(cursor.moveToNext()){
提醒提醒=新提醒();
setId(cursor.getLong(cursor.getColumnIndex(rementerDBOpenHelper.COLUMN_ID));
setTitle(cursor.getString(cursor.getColumnIndex(rementerDBOpenHelper.COLUMN_TITLE));
setDescription(cursor.getString(cursor.getColumnIndex(rementerDBOpenHelper.COLUMN_DESCRIPTION));
setLat(cursor.getDouble(cursor.getColumnIndex(rementerDBOpenHelper.COLUMN_LAT));
setLng(cursor.getDouble(cursor.getColumnIndex(rementerDBOpenHelper.COLUMN_LONG));
提醒。添加(提醒);
}
}

使用此选项生成通知

    static int uniqueID = 0 ;
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification.Builder builder = new Notification.Builder(context);
    builder.setContentTitle(title);
    builder.setContentText("text");
    builder.setTicker("Ticker");
    builder.setSmallIcon(R.drawable.icon);
    builder.setVibrate(new long[]{100, 1500});
    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    uniqueID = uniqueID + 1;
    notificationManager.notify(uniqueID, notification);

您缺少
builder.setSmallIcon(R.drawable.rementericon);
如果没有此选项,通知将不会显示。 对于
illegalargumentexception contentintent required notification
请尝试附加挂起的intent

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    Intent notificationIntent = new Intent(this,YourTargetClass.class );
                    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
                    notification.contentIntent = contentIntent;
                }
if(android.os.Build.VERSION.SDK\u INT
谢谢兄弟,我用过它,但现在我的应用程序收到n个异常IllegargumentException contentintent必需的通知如何处理它。请尝试附加挂起的意图。我想你的目标版本是Honeycom以下。要编辑我的答案吗?请检查
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    Intent notificationIntent = new Intent(this,YourTargetClass.class );
                    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
                    notification.contentIntent = contentIntent;
                }