2015-05-22 77 views
2

我需要添加一個鬧鐘預設鈴聲,並在最大音量
但我不明白我怎麼可以通過此信息來AlarmClock的.... 我在我的手機鈴聲RES /原料(內部APK)和i使用以下代碼:安卓AlarmClock的設置音量和鈴聲

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM); 
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
i.putExtra(AlarmClock.EXTRA_HOUR, oratimer); 
i.putExtra(AlarmClock.EXTRA_MINUTES, minutitimer); 
i.putExtra(AlarmClock.EXTRA_RINGTONE, saveSong(context, R.raw.song).toString()); 
i.putExtra(AlarmClock.EXTRA_SKIP_UI, true); 
context.startActivity(i); 

這是saveSong功能:

public Uri saveSong(Context context, int song) { 
    byte[] buffer = null; 
    InputStream fIn = context.getResources().openRawResource(song); 
    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 null; 
    } 

    String path = Environment.getExternalStorageDirectory()+"/Ringtones/"; 
    String filename = "song" + ".mp3"; 

    boolean exists = (new File(path)).exists(); 
    if (!exists) { 
     new File(path).mkdirs(); 
    } 
    exists = (new File(path+filename)).exists(); 
    if (!exists) { 
     FileOutputStream save; 
     try { 
      save = new FileOutputStream(path + filename); 
      save.write(buffer); 
      save.flush(); 
      save.close(); 
      context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.fromFile(new File(path + filename)))); 
     } catch (FileNotFoundException e) { 
      // TODO Auto-generated catch block 
      return null; 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      return null; 
     } 
    } 
    return Uri.fromFile(new File(path+filename)); 
} 

但報警與在默認音量的默認鈴聲製成(如70% ?)
有沒有解決這個問題的提示? TNX

回答

-1

我認爲這會爲你工作

 mp = new MediaPlayer(); 
    mp.setAudioStreamType(AudioManager.STREAM_ALARM); 
+0

對不起,我不明白這可能是有用的.... 我不使用的媒體播放器,但鬧鐘... – Trigun