1

我创建了一个应用程序,用户可以在其中插入各种科目和他们的考试日期。我的应用程序为存储在数据库中的每个科目提供了时间跨度。当为每个主题分配的时间到达时,警报应该与通知一起播放。通知正在正常发出,但没有播放警报声。请帮助我。

我的警报管理器课程是:

public class AlarmManager extends BroadcastReceiver {

sampleDatabase appdb;
SQLiteDatabase sqldb;
Cursor cursor;
int today,prev;
Intent in;

@Override
public void onReceive(Context context, Intent intent)
{
    NotificationManager manger = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.icon , "Yahrzeit" , System.currentTimeMillis());
    in = new Intent(context,FirstAppActivity.class);
    in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, in, 0);
    notification.setLatestEventInfo(context, "ALERT!!!!", "Time Over" , contentIntent);
    notification.flags = Notification.FLAG_INSISTENT;
    appdb = new sampleDatabase(context);
    sqldb = appdb.getReadableDatabase();
    cursor = sqldb.query(sampleDatabase.TABLE_SEC, null, null, null, null, null, null);
    cursor.moveToFirst();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.SECOND, 0);
    today = (int)(cal.getTimeInMillis()/1000);
    Log.e("Naga","Alarm");
    Log.e("today",Integer.toString(today));
    prev = 0;
    cursor.moveToPrevious();
    while(cursor.moveToNext())
    {
        int dbdate = cursor.getInt(cursor.getColumnIndex(sampleDatabase.ALARMSET));
        int id = cursor.getInt(cursor.getColumnIndex(sampleDatabase.ROW_ID));
        Log.e("dbdate",Integer.toString(dbdate));
        if((dbdate<=today)&&(dbdate>prev))
        {
            manger.cancelAll();
            manger.notify(1, notification);
            sqldb.execSQL("DELETE from " + sampleDatabase.TABLE + " where " + sampleDatabase.ROW_ID + "=" + id);
            sqldb.execSQL("DELETE from "+sampleDatabase.TABLE_SEC + " where " + sampleDatabase.ROW_ID + "=" + id);

        }
        prev = dbdate;
    }
    cursor.close();
    sqldb.close();

}

我用来调用这个警报管理器的代码是这样的:

 alarmintent = new Intent(getApplicationContext(),com.nagainfo.firstAp.AlarmManager.class);
                sender = PendingIntent.getBroadcast(getApplicationContext() , 0 , alarmintent , PendingIntent.FLAG_CANCEL_CURRENT | Intent.FILL_IN_DATA);            
                am = (AlarmManager) getSystemService(ALARM_SERVICE);
                am.cancel(sender);

                alarmintent = new Intent(getApplicationContext(), com.nagainfo.firstAp.AlarmManager.class);
                //alarmintent.putExtra("note","Hebrew");
                sender = PendingIntent.getBroadcast(getApplicationContext() , 0 , alarmintent , PendingIntent.FLAG_CANCEL_CURRENT | Intent.FILL_IN_DATA);
                am = (AlarmManager) getSystemService(ALARM_SERVICE);
                am.setRepeating(AlarmManager.RTC_WAKEUP, alarmtime, 60000, sender);
4

2 回答 2

1

您尚未指定使用声音。用这个 :

notification.defaults=Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE;

如果您不希望振动将其删除。关键是您必须明智地对它们进行 OR。所以,如果你也想要灯——

notification.defaults=Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE|Notification.DEFAULT_LIGHTS;
于 2012-11-14T05:55:59.070 回答
1

如果有人使用 NotificationCompat.Builder,您可以使用:

    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notifyBuilder.setSound(sound);
于 2016-06-04T02:00:19.733 回答