Search code examples
androidnotificationsfragmentandroid-activityringtone

onFragmentResult and RingtoneManager a bad romance


What I'm trying to do


I got a FragmentActivity with 3-Fragments in it, which are contectet trough a ViewPager. Now I want to show the Ringtones or Notificationtones, over the RingtoneManager. For this I created a Method, which works perfectly. Now when I want to get the Data from the RingtoneManger when I selected a tone and pressed OK. Nothing happens in my onFragmentResult().

Question


What do I need to change, that I can get the Result from the RingtoneManager?

The Code is bellow:

Best Regards

safari

Code


package de.profiler.config;

import de.profiler.R;
import de.profiler.listadapter.PhoneAdapter;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

public class Tab2Fragment extends ListFragment{

    private static final String[] content ={*******};


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
      //Nothing todo  
    }

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState){
        View v = inflater.inflate(R.layout.frag2, container, false);
        return v;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //ListAdapter erzeugen
        PhoneAdapter adapter = new PhoneAdapter(getActivity(), content);
        setListAdapter(adapter);

    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {

        int switch_id = (int) id;


        switch (switch_id){

        case 0: {
            Toast.makeText(getActivity(), "Case " + switch_id ,  500).show();
            break;
        }

        case 1:{
            Toast.makeText(getActivity(), "Case " + switch_id ,  500).show();
            break;
        }

        case 2:{

            ringtoneSelecter("ringtone");
            break;
        }

        case 3:{

            ringtoneSelecter("notification");
            break;
        }

        case 4:{
            Toast.makeText(getActivity(), "Case " + switch_id ,  500).show();
            break;
        }

        }

    }

    /**
     * Diese Methode erstellt dynamisch das Dialog-Menu um
     * einen Ringtone/Notification auszuwählen, dies passiert wie folgt:
     * what is notification than RingtoneManger.TYPE_NOTIFICATION
     * what is ringtone than RingtoneManager.TYPE_RINGTONE
     * what is all than RingtoneManager.TYPE_ALL
     * @param what
     */
   private void ringtoneSelecter(String what){

       String uri = null;
       Intent intent = new Intent( RingtoneManager.ACTION_RINGTONE_PICKER);

       if(what == "notification"){
           intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TYPE,
                   RingtoneManager.TYPE_NOTIFICATION);
       }else if(what == "ringtone"){
           intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TYPE,
                   RingtoneManager.TYPE_RINGTONE);
           intent.putExtra( RingtoneManager.EXTRA_RINGTONE_INCLUDE_DRM, true);
       }else if(what == "all"){
           intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TYPE,
                   RingtoneManager.TYPE_ALL);
       }

       intent.putExtra( RingtoneManager.EXTRA_RINGTONE_TITLE, "Select Tone");
       intent.putExtra( RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, false);
       intent.putExtra( RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);
       if( uri != null)
       {
            intent.putExtra( RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
       Uri.parse( uri));
       }

       else
       {
            intent.putExtra( RingtoneManager.EXTRA_RINGTONE_EXISTING_URI,
       (Uri)null);
       }
       startActivityForResult( intent, 999);
   }

   public void onFragmentResult(int requestCode, int resultCode, Intent data){
       super.onActivityResult(requestCode, resultCode, data);
    Toast.makeText(getActivity(), "FRAGMENT RESUME WURDE AUFGERUFEN" + data ,  500).show();
   }


}

Solution

  • What is onFragmentResult...?I think it works with onActivityResult...instead if both are in same fragment..