0

i have a app in which i used wifi as a profile changer if user is connected to wifi and he set the ringing to any one this app save the ringing tone and again when user connected to same wifi tone auto set which he last time . i dont know how to set ringing tone in android please tell me with some code. here is my code which get the current tone when connected to wifi and i want to set the current tone again how to do this?

 ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo mWifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

                if (mWifi.isConnected()) {
                    final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
                    final WifiInfo conn = wifiManager.getConnectionInfo();
                    //Toast.makeText(MainActivity.this, con.getSSID()+"",Toast.LENGTH_LONG).show();

                    if (conn.getSSID().toString().equalsIgnoreCase("\"" + homewifi + "\"")) {

                        Uri currentRintoneUri = RingtoneManager.getActualDefaultRingtoneUri(context
                                .getApplicationContext(), RingtoneManager.TYPE_RINGTONE);
                        Ringtone currentRingtone = RingtoneManager.getRingtone(context, currentRintoneUri);

                        sbVolume.refreshDrawableState();
                        sbBrightness.refreshDrawableState();

                        sharedpreferences = getSharedPreferences(MyPRE, Context.MODE_PRIVATE);
                        String current = sharedpreferences.getString(CUR, "");
                                SharedPreferences.Editor editor = sharedpreferences.edit();
                                editor.putString(CUR, String.valueOf(currentRingtone));
                                editor.commit();
                        t1.setText("Current Ringtone : "+currentRingtone.getTitle(context));
                    }
                }
faisal iqbal
  • 724
  • 1
  • 8
  • 20

1 Answers1

0
File k = new File(path, "song.mp3");

Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
Uri finalUri = this.getContentResolver().insert(uri, values);

RingtoneManager.setActualDefaultRingtoneUri(
  myActivity,
  RingtoneManager.TYPE_RINGTONE,
  finalUri
);  
Android Geek
  • 8,956
  • 2
  • 21
  • 35