1

着信音アプリケーションを作成していますが、問題があります。リストアイテムで音を鳴らしたり、着信音を設定したりできるのですが、電話の設定から確認すると鳴りません。問題はどこですか、ありがとう。

public class AndroidListViewActivity extends ListActivity {

int [] sesdosya;
    MediaPlayer mediaPlayer;     

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sesdosya= new int[]    {R.raw.aramabeni,R.raw.azsonra,R.raw.baglama,R.raw.crank,R.raw.haha,R.raw.hippopchicken,R.raw.nokiaturkish,R.raw.nuri,
              R.raw.policemix,R.raw.polistelsiz,R.raw.ramiz,R.raw.veryfunnybaby,R.raw.wahwah,R.raw.walawalabingbang,R.raw.windowsmusic};

    // storing string resources into Array
    String[] sesler = getResources().getStringArray(R.array.sesler);        
    // Binding Array to ListAdapter
    this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label,  sesler));

    ListView lv = getListView();

    // listening to single list item on click
    lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {     

          // selected item 
          String product = ((TextView) view).getText().toString();     

  // Launching new Activity on selecting single List Item            
          Intent intent = new Intent(getApplicationContext(), SingleListItem.class);
          // sending data to new activity
          intent.putExtra("position", position);
          startActivity(intent);            
      }

    private String getItemAtPosition(int position) {
        // TODO Auto-generated method stub
        return null;
    }
    });
}
}

その他のクラス; (着信音の再生と設定)

public class SingleListItem extends Activity{

 int [] sesdosya;
 String[] sesisim;
 MediaPlayer mediaPlayer;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        
    sesisim = new String[] {"aramabeni","azsonra","baglama","crank","haha","hippopchicken","nokiaturkish","nuri","policemix",
            "polistelsiz","ramiz","veryfunnybaby","wahwah","walawalabingbang","windowsmusic"}; 
    sesdosya= new int[] {R.raw.aramabeni,R.raw.azsonra,R.raw.baglama,R.raw.crank,R.raw.haha,R.raw.hippopchicken,R.raw.nokiaturkish,R.raw.nuri,
            R.raw.policemix,R.raw.polistelsiz,R.raw.ramiz,R.raw.veryfunnybaby,R.raw.wahwah,R.raw.walawalabingbang,R.raw.windowsmusic};

    this.setContentView(R.layout.single_list_item_view);

    TextView txtProduct = (TextView) findViewById(R.id.product_label);

    Intent intent = getIntent();
    int position = intent.getExtras().getInt("position");

    mediaPlayer = MediaPlayer.create(this, sesdosya[position]); 
    Button b = (Button) findViewById(R.id.button1);
    b.setOnClickListener(new View.OnClickListener(){

     public void onClick(View arg0) {                           
            mediaPlayer.start();                        
    //start the progress dialog
     }                   
    });

    Button zil = (Button) findViewById(R.id.btnzilsesi);
    zil.setOnClickListener(new View.OnClickListener(){

     public void onClick(View arg0) {            

        Intent intent = getIntent();                     
        int position = intent.getExtras().getInt("position");
        setRingtone(sesdosya[position]);                        

    //start the progress dialog
     }
    });

 }

@SuppressLint("SdCardPath")
public boolean setRingtone(int p){

    byte[] buffer=null;  
    InputStream fIn = getBaseContext().getResources().openRawResource(p);  
    int size=0;  

    try {
        size = fIn.available();
        buffer = new byte[size];
        fIn.read(buffer);
        fIn.close();
        } catch (IOException e) {
        // TODO Auto-generated catch block
        return false;
        }

    String path=Environment.getExternalStorageDirectory().getPath()+"/sdcard/media/audio/ringtones/"; 
    String filename=sesisim+".mp3";  

    boolean exists = (new File(path)).exists();  
    if (!exists){new File(path).mkdirs();}  


   sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+path+filename)));  

    File k = new File(path);  

    ContentValues values = new ContentValues();  
    values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());  
    values.put(MediaStore.MediaColumns.TITLE,filename);  
    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");  
    values.put(MediaStore.Audio.Media.ARTIST, "test1");  
    values.put(MediaStore.Audio.Media.IS_RINGTONE, true);  
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION,false);  
    values.put(MediaStore.Audio.Media.IS_ALARM, false);  
    values.put(MediaStore.Audio.Media.IS_MUSIC, false);  


    //Insert it into the database

    Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());

   getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + k.getAbsolutePath() + "\"", null);

    Uri newUri = getContentResolver().insert(uri, values);

    RingtoneManager.setActualDefaultRingtoneUri(
            SingleListItem.this,
      RingtoneManager.TYPE_RINGTONE,
      newUri
    );
    return true;

   }  
}
4

0 に答える 0