I need to sound an alarm ringtone after a layout popup with a stop button... I had use if else, if (usenotification), I'm able to make a ringtone sounds
but in else (), it doesn't work..
This is my code:
public class AlarmActivity extends Activity {
Uri uriRingtone;
Ringtone ringTone;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alarm);
uriRingtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if (alarmSound == null) {
ringTone = RingtoneManager
.getRingtone(getApplicationContext(), uriRingtone);
}
uriRingtone = alarmSound;
}
}
*the if part works... only else doesnt... // another part of java
public class OnAlarmReceiver extends BroadcastReceiver {
private static final int NOTIFY_ME_ID = 1337;
Uri uriRingtone;
Ringtone ringTone;
@Override
public void onReceive(Context ctxt, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctxt);
boolean useNotification = prefs.getBoolean("use_notification", true);
if (useNotification) {
NotificationManager mgr = (NotificationManager) ctxt
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.stat_notify_chat, "It's Lunch time!", System.currentTimeMillis());
PendingIntent i = PendingIntent.getActivity(ctxt, 0, new Intent(ctxt, AlarmActivity.class), 0);
note.setLatestEventInfo(ctxt, "Lunch!", i);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if(alarmSound == null){
alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
}
note.sound = alarmSound;
note.flags |= Notification.FLAG_AUTO_CANCEL;
mgr.notify(NOTIFY_ME_ID, note);
} else {
Intent i = new Intent(ctxt, AlarmActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity(i);
}
}
}