Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Android studio Ringtonemanager.TYPE_RINGTONE_Android_Alarm - Fatal编程技术网

如何使用Android studio Ringtonemanager.TYPE_RINGTONE

如何使用Android studio Ringtonemanager.TYPE_RINGTONE,android,alarm,Android,Alarm,我需要发出警报铃声后,布局弹出一个停止按钮。。。 如果不是这样的话,我也有用, 如果(使用通知),我可以发出铃声 但在else()中,它不起作用 这是我的代码: public class AlarmActivity extends Activity { Uri uriRingtone; Ringtone ringTone; @Override public void onCreate(Bundle savedInstanceState) { s

我需要发出警报铃声后,布局弹出一个停止按钮。。。 如果不是这样的话,我也有用, 如果(使用通知),我可以发出铃声

但在else()中,它不起作用

这是我的代码:

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;
    }
}
*如果部分工作正常。。。只有其他人不…//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);

        }
    }
}

您在上面的代码中是否也尝试了
if/else
示例?不,它在OnAlarmReceiver中。。请参阅我的编辑。。非常感谢您的帮助。我设法使if(usenotification)正常工作。。。但是当AlarmActivity intent被调用时,我需要else发出铃声@Summea在我的应用程序中,用户可以选中“使用通知”(android)或取消选中。如果未选中,当警报响起时,它将打开我的新意图(AlarmActivity),但是没有铃声..嘿!当我按下停止按钮/主页/返回时,它在Summea下工作。现在我必须使声音停止