android如何设置铃声,在shareprefrences中保存当前音调并再次设置它

时间:2016-06-14 10:57:38

标签: android

我有一个应用程序,其中我使用wifi作为配置文件更换器,如果用户连接到wifi,他设置振铃到任何一个这个应用程序保存铃声再次当用户连接到相同的wifi音调自动设置,他持续时间 。我不知道如何在Android中设置铃声请告诉​​我一些代码。 这是我的代码,当连接到wifi时获得当前音调,我想再次设置当前音调如何做到这一点?

 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));
                    }
                }

1 个答案:

答案 0 :(得分: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
);