-6

Sorry i am a beginner and i am not sure why there is this error which is at the get activity context line,this is the code please help me out here,i am trying to activate a ringtone from the broadcast receiver program(alarm)

public class OnAlarmReceiver extends BroadcastReceiver {
private static final int NOTIFY_ME_ID = 1337;

Ringtone ringTone;
Uri uriRingtone;


@Override
public void onReceive(Context ctxt, Intent intent) {
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(ctxt);
    boolean useNotification = prefs.getBoolean("use_notification", true);

    uriRingtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

    ringTone = RingtoneManager.getRingtone(getactivityContext(), uriRingtone);
    ringTone.play();

    if (useNotification) {
        NotificationManager mgr = (NotificationManager)
                ctxt.getSystemService(Context.NOTIFICATION_SERVICE);
        PendingIntent i = PendingIntent.getActivity(ctxt, 0, new Intent(ctxt, AlarmActivity.class), 0);
        Notification note = new Notification.Builder(ctxt)
                .setContentTitle("Restaurant List")
                .setContentText("It's time for lunch!")
                .setSmallIcon(android.R.drawable.stat_notify_chat)
                .setContentIntent(i)
                .setAutoCancel(true).build();
        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);
    }
}
}
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Novice
  • 3
  • 1

1 Answers1

1

Use this

ringTone = RingtoneManager.getRingtone(ctxt, uriRingtone);

Instead of this

ringTone = RingtoneManager.getRingtone(getactivityContext(), uriRingtone);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163