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

誰かが NotificationCompat.Builder を使用している場合は、次を使用できます。

    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    notifyBuilder.setSound(sound);
于 2016-06-04T02:00:19.733 に答える
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 に答える