我正在使用铃声管理器开发简单的应用程序。我可以为来电号码设置特定的铃声。但问题是我的铃声工作正常,当第二次拨打号码时。我需要首次覆盖默认铃声。我怎样才能做到这一点。以下是我的代码段。
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)
{
}
}
}
答案 0 :(得分:0)
我认为您的主要问题是,在收到收入电话时您正在更改铃声。你应该改变这种方法,现在我有两种可能的情况: