Android设备设备报警音定制

时间:2014-03-07 10:08:10

标签: android media-player alarmmanager

我想创建一个应用程序,通过点击播放选定的音调。我完成了显示系统警报列表的列表,但是无法在点击时播放。我发现了一个代码,但它只播放默认闹钟而没有选择一个......请帮助我.......我的代码在这里......

public class GamesFragment extends Fragment {
    Uri uri;
    //public String chosenRingtone;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_games, container, false);
        Button btn=(Button)rootView.findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener() {

            private String chosenRingtone;

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //Toast.makeText(getActivity(), "hi", 2000).show();

                Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_ALARM);
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
                intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
                getActivity().startActivityForResult(intent, 5);

            }



            public void onActivityResult(final int requestCode, final int resultCode, final Intent intent)
             {
                // TODO Auto-generated method stub
                 if (resultCode == Activity.RESULT_OK && requestCode == 5)
                 {
                       uri = intent.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

                      if (uri != null)
                      {
                          this.chosenRingtone = uri.toString();
                      }
                      else
                      {
                          this.chosenRingtone = null;
                      }
                  }          
            }

        public void setChosenRingtone(String chosenRingtone) {
            this.chosenRingtone = chosenRingtone;
        }   //RingtoneManager.setDefaultUri(chosenRingtone.TYPE_NOTIFICATION);
        });


    Button bttn=(Button)rootView.findViewById(R.id.play);   
    bttn.setOnClickListener(new OnClickListener() {



        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Toast.makeText(getActivity(), "hi", 2000).show();
            //Ringtone r = RingtoneManager.getRingtone(getActivity(), uri);
            //chosenRingtone.play();


        }
    });
        return rootView;
    }
}

0 个答案:

没有答案