Saturday, February 11, 2012

[android-developers] Modify Audio Settings when my phone gets a call from a specific number

Hi All,

I have been trying very hard to get it work in my Gingerbread 2.3.5
phone but with no success. I have read all the posts and have come up
with the below code which works very rarely. I suspect it has
permissions issue but could not zero in on the issue which is bugging
me for long.

My Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="utils.self.puttu"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />

<uses-permission
android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE" />

<application >
<receiver android:name=".PersonalisedSetting" >
<intent-filter >
<action
android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>

</manifest>

My Receiver:

package utils.self.puttu;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.telephony.TelephonyManager;
import android.widget.Toast;

public class PersonalisedSetting extends BroadcastReceiver {
// private PhoneStateListener myListener = null;
@Override
public void onReceive(Context context, Intent intent) {

// if (intent.getStringExtra(TelephonyManager.EXTRA_STATE) ==
// TelephonyManager.CALL_STATE_RINGING)

String number = intent
.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

if (number.equals("+919742431366") || number.equals("9742431366"))
{ // My Gf's Number :D
AudioManager vAudioManager = (AudioManager) context
.getSystemService(Context.AUDIO_SERVICE);
int maxVolume = vAudioManager
.getStreamMaxVolume(AudioManager.STREAM_RING);

vAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
vAudioManager.setStreamVolume(AudioManager.STREAM_RING, maxVolume,
AudioManager.FLAG_SHOW_UI);
} else {
Toast.makeText(context, "Forget it", Toast.LENGTH_LONG).show();
}

}

}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment