安卓闹钟声音不工作

标签 android android-alarms

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

我的警报管理器类是:

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);

最佳答案

您没有指定使用声音。使用这个:

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

如果您不想振动,请将其删除。关键是你必须明智地或他们。所以,如果你也想要灯 -

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

关于安卓闹钟声音不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13373705/

相关文章:

android - 用于实例化 ViewModel 的首选 Fragment 生命周期方法

java - Android模拟运行dexer失败(Win 7)

android - 显示从某个开始日期到某个结束日期的重复通知

Android 警报管理器 setExactAndAllowWhileIdle() 在打盹模式下的 Android 7.0 Nougat 中不起作用

java - 如果时区与 GMT(UTC) 不同,AlarmManager 会在错误的时间发出警报

android - 从 Android 连接到 XMPP 服务器

java - 如何使用 Sprite 作为另一个 Sprite 的 anchor ?

Android:警报在预定时间之前被触发

android - 应用程序关闭时警报不起作用

android - PayPal 如何支持未在支持中列出的货币?