I need my app to pop up a message on incoming call if the battery is critically low. Is there any way to do this(and if possible cut the call)? searching in the net didnot help me much.
Asked
Active
Viewed 1,155 times
0
-
First - catch the incoming call: http://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html Second - read battery state: http://www.tutorialforandroid.com/2009/01/getting-battery-information-on-android.html Third - end incoming call: http://stackoverflow.com/questions/15481524/how-to-programatically-answer-end-a-call-in-android-4-1 For all this you have to use `BradcastReceivers` and `Intents`. And, I guess, you will need to have a `service` in order to accomplish your task – Boris Mocialov Jun 28 '13 at 17:23
-
what exactly couldn't you find on the net..? – Boris Mocialov Jun 28 '13 at 17:38
-
Can I toast or pop dialogue box when phone rings? – Sreekanth Karumanaghat Jun 28 '13 at 17:43
-
dialogue from service - http://stackoverflow.com/questions/3599563/android-alert-dialog-from-service . `Toast` will work fine – Boris Mocialov Jun 28 '13 at 17:44
-
My friend says nothing can be done when a call comes till it gets cut, because android gives first priority to calls and they can't be interrupted. I am really confused. Any clue? – Sreekanth Karumanaghat Jun 28 '13 at 18:02
-
I dunno, try implementing and see what happens – Boris Mocialov Jun 28 '13 at 18:02
-
After a brief googling i found that it is possible, but not on all devices and not on all API levels. But i might be wrong – Boris Mocialov Jun 28 '13 at 18:09
1 Answers
0
Use this for showing something during incoming call
public class IncomingCallReciever extends BroadcastReceiver {
private Context mContext;
private Intent mIntent;
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
mIntent = intent;
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
int events = PhoneStateListener.LISTEN_CALL_STATE;
tm.listen(phoneStateListener, events);
}
private final PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
String callState = "UNKNOWN";
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
callState = "IDLE";
break;
case TelephonyManager.CALL_STATE_RINGING:
// write your code display Toast or Dialog
break;
}
Log.i(">>>Broadcast", "onCallStateChanged " + callState);
super.onCallStateChanged(state, incomingNumber);
}
};
}
Declare this way in your menifest file
<receiver android:name=".IncomingCallReciever"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"></action>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
Add Following Permission
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

Singh Arjun
- 2,454
- 1
- 16
- 13