如何从我的应用程序设置警报音?

时间:2011-07-28 13:13:44

标签: android

如何从我的应用程序中设置警报音?

主要问题是我设置警报超过一次,但只有第二次警报正在工作,对不起英语不好。

提前致谢。

if(day.equals("Daily")){
    System.out.println("Daily Alarm");
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() +(seconds * 1000) , (24 * 60 * 60 * 1000) ,pendingIntent);
    Toast.makeText(this, "Alarm set for Daily", Toast.LENGTH_LONG).show();
}else{
    System.out.println("Weekly Alarm");
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() +(seconds * 1000) , (7 * 24 * 60 * 60 * 1000) ,pendingIntent);
    Toast.makeText(this, "Alarm set for "+day, Toast.LENGTH_LONG).show();
}

以下用于Pick音的代码: -

String uri = null;
intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE,RingtoneManager.TYPE_NOTIFICATION);
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");

if (uri != null) {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,Uri.parse(uri));
} else {
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,(Uri) null);
}
startActivityForResult(intent, 0);

startActivityForResult方法: -

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            Uri uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
            if (uri != null) {
                @SuppressWarnings("unused")
                String ringTonePath = uri.toString();
            }
        }
}

请帮助我。

1 个答案:

答案 0 :(得分:0)

Intent i1 = new Intent("com.android.MY_ACTION_A") //Scheduled 1st using a PendingIntent
Intent i2 = new Intent("com.android.MY_ACTION_B") //Scheduled 2st using a PendingIntent

如果您使用相同的组件(IntentSender - 您的活动,服务)来安排警报,则只有最新的组件才能运行。在上述情况下, i1 将被取消。