我正在创建一个骑车制作应用程序,在该应用程序中我需要为特定文本设置警报/铃声
public class RefreshReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("com.package.ACTION_CLASS_TrackYourRide_REFRESH_Arrived_Driver")) {
System.out.println("triparrived----------------------");
Tv_headerTitle.setText("Driver Arrived");
rl_endTrip.setVisibility(View.GONE);
track_your_ride_view1.setVisibility(View.GONE);
}else if(intent.getAction().equals("com.package.ACTION_CLASS_TrackYourRide_REFRESH_BeginTrip")){
System.out.println("tripbegin----------------------");
Tv_headerTitle.setText("Enjoy the RYDD");
rl_endTrip.setVisibility(View.GONE);
track_your_ride_view1.setVisibility(View.GONE);
panic_btn.setVisibility(View.VISIBLE);
}
在上面的代码中,设置闹钟,当驱动程序到达文本时。当app在前台时,如何为特定文本设置声音。
答案 0 :(得分:0)
我在How to play ringtone/alarm sound in Android
找到答案try {
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
} catch (Exception e) {
e.printStackTrace();
}