To block the out going call from my android app. - android

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>

Related

No listener when call state reject on voice phone

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>

How to make BroadcastReceiver work after reboot?

I have a written a program which intercepts incoming call using BroadcastReceiver. When I start my app, it starts working. Now the problem is when I restart my android phone, this BroadcastReceiver doesn't work. So I am assuming that I need to make a service for this. But I don't know when to start service and where to start BroadcastReceiver.
BroadcastReceiver code -
public class CallInterceptor extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Service started", Toast.LENGTH_LONG).show();
Bundle extras = intent.getExtras();
if (extras != null) {
String state = extras.getString(TelephonyManager.EXTRA_STATE);
Toast.makeText(context, "Phone is " + state, Toast.LENGTH_LONG).show();
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = extras
.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, "Call from " + phoneNumber, Toast.LENGTH_LONG).show();
//sendSMS(phoneNumber);
//toggle ringer mode
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
toggleMode(am);
}
}
}
AndroidManifest file -
<receiver android:name="com.nagarro.service.CallInterceptor" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" >
<action android:name="android.intent.action.BOOT_COMPLETED" />
</action>
</intent-filter>
</receiver>
I don't think <action android:name="android.intent.action.BOOT_COMPLETED" /> is working.
Also, is it possible to do this without service? Please suggest approach which will help me to intercept call evertime (even after reboot).
You've improperly closed your first action tag. Your receiver section should look like:
<receiver android:name="com.nagarro.service.CallInterceptor" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Also, you are not using a Service. You're using a Broadcast Receiver.
See this page for the basics Application Fundamentals.

Handling incoming call in android

In my app i want to detect incoming call and i want to hide default incoming call layout with my custom layout,far now i have managed to get the state of incoming call but i'm not able to hide the default incoming call screen...below is my code and my android manifest file...any help will be appreciated..
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i("DEBUG", "on recive called");
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (TelephonyManager.EXTRA_STATE_RINGING.equals(state))
{
abortBroadcast();
Log.d("MPR", "Its Ringing [" + number + "]");
//start activity
Intent i = new Intent();
i.setClassName("com.ezest.callerid", "com.ezest.callerid.CustomCallActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
if (TelephonyManager.EXTRA_STATE_IDLE.equals(state))
{
Log.d("MPR", "Its Idle");
}
if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(state))
{
Log.d("MPR", "Its OffHook");
}
}
Manifest
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<receiver android:name="MYPhoneStateListener">
<intent-filter android:priority="999999">
<action android:name="android.intent.action.PHONE_STATE"></action>
</intent-filter>
</receiver>
<activity
android:label="#string/app_name"
android:name=".CallerIDActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="CustomCallActivity">
</activity>
</application>
when defined action is happened android operating system send broadcast to all defined broadcastreceiver for this action. it does this job according to priority order. I can see you have done it. copy that code where you want to cancel broadcast.
abortBroadcast()
Android operating system will stop broadcasting to other broadcastreceivers

The CAMERA_BUTTON intent cannot be caught by receiver [duplicate]

I saw many posts in StackOverflow regarding how to listen to camera events, and got few information but still there are few questions remain in my mind please let me know the answers for these:
I have an application which have a broadcast receiver and my broadcast receiver will lauch my activity, but the main purpose of having broadcast receiver is to listen to camera photo/video capture intent.
I want to know which is the intent i have to listen for this, and is it possible to do in this way.
thanks
For Receiving camera photo capture intent, try following code
public class CameraEventReciver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "New Photo Clicked", Toast.LENGTH_LONG).show();
}
and in manifest, register the receiver:-
<uses-permission android:name="android.permission.CAMERA" />
<receiver
android:name="com.android.application.CameraEventReciver"
android:enabled="true" >
<intent-filter>
<action android:name="com.android.camera.NEW_PICTURE" />
<data android:mimeType="image/*" />
</intent-filter>
</receiver>
In your Android Manifest, you need to specify which intents you want to receive. For camera that'd be the following code (this goes within the <application> tags):
<receiver android:name="com.receiver.CameraReceiver">
<intent-filter android:priority="10000">
<action android:name="android.intent.action.CAMERA_BUTTON" />
</intent-filter>
</receiver>
In addition to that, you should add this to your <intent-filter> within the <activity> tags:
<category android:name="android.intent.category.DEFAULT" />
Finally, take care of the event in your activity's code like so:
#Override
public void onReceive(Context context, Intent intent) {
abortBroadcast();
//TODO: your code here
}
You can use thread that will control your directory camera like:
FileObserver observer =new FileObserver("/mnt/extSd/DCIM/Camera/"){
#Override
public void onEvent(int event, String file) {
// TODO Auto-generated method stub
if(event == FileObserver.CREATE ){
//Do Some things With The file
}
}};
} catch (FileNotFoundException e) {
e.printStackTrace();
}
observer.startWatching();

How to show incoming call notification in android application

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

Categories

Resources