I want to display one dialog box after incoming call, so that I can run my application in background while receiving call.
How to catch that incoming call in android application???
In AndroidManifest.xml you shoud make a receiver:
<receiver android:name="IncomingCallInterceptor">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
and declare permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Then,
public class IncomingCallInterceptor extends BroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
// Phone is ringing
}
}
}
Maybe this broadcast intent is what you need ACTION_PHONE_STATE_CHANGED
Related
My app need to know if the user is current on a phone call or not, then do some response accordingly.
All I need to know if the user is on a phone call or not. I do not need any other rights to deal with anything related to the phone number or any personal information of the user.
What should I do to achieve this? Do I need to get user's permission for it?enter code here
Yes First add these permission to your Manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
You should use Broadcast Receiver with this intent filters.
android.intent.action.NEW_OUTGOING_CALL
android.intent.action.NEW_INCOMING_CALL
You can use service for this register. Something like these:
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
registerReceiver(receiver,new IntentFilter("android.intent.action.NEW_OUTGOING_CALL"));
registerReceiver(receiver2,new IntentFilter("android.intent.action.NEW_INCOMING_CALL"));
return START_STICKY;
}
And our Broadcast receiver you can use this:
public class CallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
//
RequestQueue
String savedNumber="";
String savedNumber2= intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
}
Log.e("Saved number","Numara: "+savedNumber);
Log.e("İt is ","İt is it");
Log.e("Saved number 2 ",savedNumber2);
}
}
And lastly in your manifest file you could use intent filter in your receiver like these:
<receiver
android:name=".CallReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
iam using app to phone sinch call, when user execute call, everything fine from call progressing until call ended, but when another user reject the phone call, listener from first user not return anything, is there any clue/information about this, really appreciate anything to make it clear.
For this you need to create a BroadcastReceiver which receive your call state and using that you can implement your another logic.
Here is demo for call receiver :
public class IncomingCallReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (TelephonyManager.EXTRA_STATE_RINGING.equals(intent.getStringExtra(TelephonyManager.EXTRA_STATE))){
Log.d("mytag","call ringing");
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
// Toast.makeText(context, incomingNumber, Toast.LENGTH_LONG).show();
}
if (TelephonyManager.EXTRA_STATE_IDLE.equals(intent.getStringExtra(TelephonyManager.EXTRA_STATE))){
String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, "Call Ended.", Toast.LENGTH_LONG).show();
}
}
}
Add these in your manifest file :
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<receiver
android:name=".phonemidea.IncomingCallReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
I am making an app in which I want to start a service as soon as there is an incoming call. What are the various ways to do this in android?
I know broadcast receiver is one way, but I couldn't find any broadcast intent for incoming phone call.
Use action PHONE_STATE to detect incoming calls..
add this to manifest
<receiver android:name="com.example.YourReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
And your receiver
public class YourReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
// This code will execute when the phone has an incoming call
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_IDLE)
|| intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_OFFHOOK)) {
// This code will execute when the call is disconnected
}
}
}
How would I have an activity or animation start when the users device receives an sms? I want to start/play an animation when a sms comes in while they are viewing my app. How would I go about doing that?
public class SmsReceiver extends BroadcastReceiver {
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(SMS_RECEIVED)) {
// here start the activity for animation or whatever you want to do
}
}
}
add this permission to your manifest
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
add the receiver under your application tag in your manifest
<receiver android:name=".SmsReceiver" >
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" >
</action>
</intent-filter>
</receiver>
Create a BroadcastReceiver for SMS
http://developer.android.com/reference/android/content/BroadcastReceiver.html
and act accordingly
SO Example if you had used search:
Android - SMS Broadcast receiver
I want to make an application in which once the application starts, it will show two button(start and stop button) and once the user clicks the start button the call function will be blocked for the time period till the user again start the application and click the stop button to stop this function. any help please its urgent
in short I Will tell I want to block the outgoing call from my phone by using this activity only
please is there any way to do so???
You can block the outgoing call using the setResultData(null) function in the onReceive method of the Broaadcast receiver.
public class BlockOutgoing extends BroadcastReceiver
{
String number;
#Override
public void onReceive(Context context, Intent intent)
{
Log.d("12280", "asdasNumber is-->> " + number);
number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
setResultData(null);
Toast.makeText(context, "Outgoing Call Blocked" , 5000).show();
}
}
In the manifest file, you need to register the receiver like this,
<receiver
android:name=".BlockOutgoing"
android:label="#string/app_name" >
<intent-filter android:priority="1">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
Also define the permission to intercept the outgoing call,
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
Edit-
To unregister a broadcast receiver, follow this link
public class BlockOutgoing extends BroadcastReceiver {
String number;
#SuppressLint("WrongConstant")
#Override
public void onReceive(Context context, Intent intent)
{
// Log.d("12280", "asdasNumber is-->> " + number);
number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
setResultData(null);
Toast.makeText(context, "Outgoing Call Blocked" , 5000).show();
}
}
<receiver
android:name=".BlockOutgoing"
android:label="#string/app_name" >
<intent-filter android:priority="1">
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>