程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-程序的警報鈴聲不響怎麼辦

android-程序的警報鈴聲不響怎麼辦

編輯:編程綜合問答
程序的警報鈴聲不響怎麼辦

我創建了一個應用,用戶可以添加日程主題,然後在應用裡設置每個日程的限定時間,到了一個日程的限定時間之後,應用就會進行提醒,還有鈴聲,但是現在提醒消息可以正常出來,沒有鈴聲,請高手幫我看一下代碼出錯在那裡?謝謝

鈴聲manager class:

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;
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved