I want to create an android application that changes the mode to ringing from vibration when incoming call from particular number
Asked
Active
Viewed 714 times
-1
-
For that you need Eclipse + android SDK and bit of Google search!! – Vipul Jun 20 '12 at 10:50
1 Answers
0
For Changing ringing from vibration on incoming call use Use TelephonyManager,AudioManager and PhoneStateListener
as:
TelephonyManager mTelephonyMgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
mTelephonyMgr.listen(new TeleListener(), PhoneStateListener.LISTEN_CALL_STATE);
class TeleListener extends PhoneStateListener
{
public void onCallStateChanged(int state, String incomingNumber)
{
super.onCallStateChanged(state, incomingNumber);
switch (state)
{
case TelephonyManager.CALL_STATE_IDLE:
//CALL_STATE_IDLE;
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//CALL_STATE_OFFHOOK;
break;
case TelephonyManager.CALL_STATE_RINGING:
//CALL_STATE_RINGING
//CHECK YOUR PARTICULAR NUMBER HERE
if(incomingNumber=="1234567890")
{
// USE AudioManager for Settingringing from vibration
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
switch (am.getRingerMode()) {
case AudioManager.RINGER_MODE_NORMAL:
Log.i("MyApp","NORMAL mode");
am.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
break;
}
}
else
{
//DO SOMETHING HERE
}
break;
default:
break;
}
}
}
add <uses-permission android:name="android.permission.READ_PHONE_STATE">
permission in manifest.xml
or How we Get Phone State using BroadcastReceiver see this tutorial:
Get Phone State When Someone is calling using BroadcastReceiver Example
-
i want to change the state to ringing for particular number not for all – Supreet Singh Sekhon Jun 20 '12 at 11:10
-
ok @SupreetSinghSekhon then u just change back `RINGER_MODE_VIBRATE` to `RINGER_MODE_NORMAL` in `TelephonyManager.CALL_STATE_IDLE` means when phone is idle – ρяσѕρєя K Jun 20 '12 at 11:12
-
i am getting runtine exception..."Unfortunately Application stops" – Supreet Singh Sekhon Jun 20 '12 at 11:22
-
i am not able to find exception. When i am running the application its showing "Unfortunately application stopped" – Supreet Singh Sekhon Jun 20 '12 at 11:35
-
ok when u have logcat stack-trace then post it but u are doing in right way just go with tutorial as is mention in my answer.thanks – ρяσѕρєя K Jun 20 '12 at 11:38
-
The exception is : Caused by: java.lang.ClassCastException: com.audio.TeleListener cannot be cast to android.app.Activity – Supreet Singh Sekhon Jun 20 '12 at 11:47