着メロマネージャーを使って簡単なアプリを開発しています。着信番号に特定の着信音を設定できます。しかし、問題は、着信番号が 2 回目に呼び出されたときに、着信音が正常に機能することです。デフォルトの着信音自体を初めてオーバーライドする必要があります。どうすればこれを達成できますか。以下は私のコードスニペットです。
public class IncomingCallReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if(null == bundle)
return;
try {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);
Bundle b = intent.getExtras();
incommingNumber = b.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
incom_call=incommingNumber;
// Get Current Time
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
currentTime=today.format("%k:%M");
try
{
currentTime_int = Integer.parseInt(currentTime.replaceAll("[^0-9.]",""));
}
catch(NumberFormatException nfe)
{
}
try
{
contacts_db = new ContactsDB(context);
contacts_db.open();
Utilities.writeIntoLog("DB open");
cursor = contacts_db.fetchGroupName_fromContacttable(incom_call,op_flag);
if( cursor != null )
{
cursor.moveToFirst();
groupname = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDB.KEY_GROUPNAME));
contactname = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDB.KEY_FIRSTNAME));
}
cursor.close();
contacts_db.close();
}
catch (Exception e)
{
}
try
{
contacts_db = new ContactsDB(context);
contacts_db.open();
cursor = contacts_db.fetchDnD_Detail_fromGrouptable(groupname);
if( cursor != null )
{
cursor.moveToFirst();
ringtonepath = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDB.KEY_GROUPRINGTONE_INGROUPTABLE));
dnd_start_time = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDB.KEY_GROUP_DND_STARTTIME));
dnd_end_time = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDB.KEY_GROUP_DND_ENDTIME));
dnd_ring_mode = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDB.KEY_GROUP_DND_RINGMODE));
}
cursor.close();
contacts_db.close();
}
catch (Exception e)
{
}
dnd_starttime_int = Integer.parseInt(dnd_start_time.replaceAll("[^0-9.]",""));
dnd_endtime_int = Integer.parseInt(dnd_end_time.replaceAll("[^0-9.]",""));
if(currentTime_int>=dnd_starttime_int && currentTime_int<=dnd_endtime_int)
{
if(dnd_ring_mode.equals("Silent"))
{
mobilemode = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); mobilemode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
else
{
mobilemode = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); mobilemode.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}
}
else
{
mobilemode = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Uri ruri = Uri.parse(ringtonepath); RingtoneManager.setActualDefaultRingtoneUri(context,RingtoneManager.TYPE_RINGTONE, ruri);
}
}
catch (Exception e)
{
}
}
}