Replace native outgoing call Screen by custom screen android - android

I am trying to launch my custom screen on top of native outgoing caller screen that may contain full Screen image of Caller and some buttons for actions like reject call. Using this I am able to make call, but is redirecting me to native caller screen...
How to replace\override the default call screen by my custom screen screen?
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phonenumber)));
public class GetOutgoingNUmber extends BroadcastReceiver {
final static String INTENT_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.v("DileBroadCastReceiver","In onReceive()");
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
Intent i = new Intent(context, OutGoingScreen.class);
i.putExtras(intent);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(i);
}
}, 1000);
}
here OutGoingScreen is for displaying outgoing screen
public class OutGoingScreen extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.outgoingscreen );
}
}
Now the problem is it is showing my screen for few msec and again showing native screen....?

Write a receiver for outgoing call
public class OutgoingCallReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, final Intent intent) {
//Write intent for yout page
}
}
add these to Manifest
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<receiver android:name=.OutgoingCallReceiver" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
add below theme to activity theme
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"
Open you intent after 1 second bcoz the original outgoing call screen takes 800ms to open so you need to over lay that screen, so you must call intent after 800ms.
it works for me.

The best way to do so is develop your own Phone app and expect the user to set it as the default app for making calls.
Edit:
Add an Activity which accepts ACTION_DIAL intent and have a numeric keypad and then once user has entered the call number, you can fire ACTION_CALL intent with the phone number which would invoke the native phone app. This way also, the user has to select your app to be set as default one for ACTION_DIAL intent.

You don't need to create a separate application.
Ultimately you just want to handle the new outgoing call requests,so create a BroadcastReceiver to listen the event of ACTION_NEW_OUTGOING_CALL,and create an Activity to invoke upon that event.
you will need to specify permission in manifest file about PROCESS_OUTGOING_CALLS.
Have a look at some references:
handling-phone-call-requests-right-way
android-dialer-application
I hope it will be helpful !

Related

How to perform action on a specific number dial in android?

I want a service to monitor the calls I dial, and to perform a specific task parallel to a specific call.
Example. I call 123 from the dialer and a specific task gets triggered at that time.
But if I dial some other number then nothing should happen.
How can I implement such a thing?
You can use BroadcastReceiver for ACTION_NEW_OUTGOING_CALL
public class OutgoingBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (intent. getAction (). equals (Intent. ACTION_NEW_OUTGOING_CALL)) {
String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.e("Number=", number);
if (number.equals("123")) {
// do your magic here
}
}
}
And don't forget and using permission:
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />

Log Android user wakeup/unlock

I'm trying to create an application that has a constant running service which will log and display to the user everytime they unlock or change the phones state from screen off to screen on.
Is this possible without using the Log cat through the P.C?
Yes you can do it using Broadcast Receiver. Android system sends always broadcasts for specified changes. You can handle this broadcasts using Broadcast Receiver.
Example:
We will create a new Broadcast Receiver to handle the Screen On and Screen Off state:
public class PhoneStateBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
//we will handle here the activities which will tell us that
// the screen state has changed
if(intent.getAction().equals(Intent.ACTION_SCREEN_OFF)){
//write log that the screen is off
}else if(intent.getAction().equals(Intent.ACTION_SCREEN_ON)){
//write log that the screen is on
}
}
}
All what you need is to declare this BroadcastReceiver in Android Manifest.xml
file:
<receiver android:name="yourpackage.PhoneStateBroadcastReceiver">
<intent-filter>
</intent-filter>
</receiver>
And after that you should start your PhoneStateBroadcastReceiver on yout
Service onCreate Method:
//...
public void onCreate(){
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
PhoneStateBroadcastReceiver pSReciever = new PhoneStateBroadcastReceiver();
registerReceiver(pSReciever, filter);
}

Is there a way to call finish() on all running activities inside application?

Well, my question is just as simple as in the title:
Is there a way to call finish() on all running activities inside application ?
So i need a way to completly shut down my app.
You can achieve that with a BroadCastReceiver:
In every activity put:
private BroadcastReceiver mLoggedOutReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
finish();
}
};
Register receiver in onCreate:
registerReceiver(mLoggedOutReceiver, new IntentFilter(Preferences.INTENT_ACTION_LOGGED_OUT));
on onDestroy:
#Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(mLoggedOutReceiver);
}
on manifest for every activity and the following filter:
<intent-filter>
<action android:name="com.example.intent.action.LOGGED_OUT" />
</intent-filter>
I have the intent Action declared in Preference class like this:
public static final String INTENT_ACTION_LOGGED_OUT = "com.example.intent.action.LOGGED_OUT";//logout
And finally all you have to do is call sendBroadcast from an exit button or something:
sendBroadcast(new Intent(Preferences.INTENT_ACTION_LOGGED_OUT));//logout
Hope this helps.
android.os.Process.killProcess(android.os.Process.myPid());
this code can shut down your app.
NO
but you can exist hole application like System.exit(0); but it is not the recomanded way..as android not design to exit the application.

broadcastreceiver onReceive problem ACTION_MEDIA_BUTTON Android

I've found a lot of pages about this in the web, but none of them helped me. I've been for hours stucked in this problem. That's why i decided to make my own question.
What I want to do is an application that receives an intent of the type ACTION_MEDIA_BUTTON and the method onReceive() of the Broadcastreceiver does something.
My Activity is like this:
public class MusicControlActivity extends Activity {
private MediaButtonIntentReceiver receiver = new MediaButtonIntentReceiver();
#Override
public void onCreate(Bundle p_SavedInstanceState) {
super.onCreate(p_SavedInstanceState);
setContentView(R.layout.main);
IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);
filter.setPriority(1000);
registerReceiver(receiver,filter);
}
#Override
public void onDestroy()
{
unregisterReceiver(receiver);
}
And my broadcastreceiver as follow:
public class MediaButtonIntentReceiver extends BroadcastReceiver {
public MediaButtonIntentReceiver()
{
super();
}
#Override
public void onReceive(Context context, Intent intent)
{
String v_IntentAction = intent.getAction();
if (!Intent.ACTION_MEDIA_BUTTON.equals(v_IntentAction)) {
return;
}
KeyEvent v_Event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (v_Event == null) {
return;
}
int v_Action = v_Event.getAction();
if (v_Action == KeyEvent.ACTION_DOWN) {
// do something
Toast.makeText(context, "BUTTON PRESSED!", Toast.LENGTH_SHORT).show();
}
abortBroadcast();
}
}
The problem is that it doesn't work, no matter what I do. I've tried registering it dynamically with registerReceiver as in the code above. Also I've tried statically in the AndroidManifest.xml like this:
<receiver android:name=".MediaButtonIntentReceiver" android:enabled="true">
<intent-filter android:priority="10000000">
<action android:name="android.intent.action.ACTION_MEDIA_BUTTON" />
</intent-filter>
</receiver>
And as you can see I've set the priority to a high level and even though it doesn't work.
I've been on this for the whole day and I don't know what to do. The method onReceive from the broadcastreceiver isn't called anytime.
Does anyone know what should I do?
Use android.intent.action.MEDIA_BUTTON Instead in your manifest. Check : http://developer.android.com/training/managing-audio/volume-playback.html
First, you should stop using Toast as your diagnostic test. Use the Log class to log to LogCat, or breakpoints, or something.
Next, you should get rid of your MediaButtonIntentReceiver constructor, as it is not needed.
Then, I would dump the if (!Intent.ACTION_MEDIA_BUTTON.equals(v_IntentAction)) block, since it is also not needed.
Next, I would make sure that your media button actually works. Does it control other applications, like a music player? It may be that your media button is not Android-compliant or something.

Intent not received by activity

I have a main activity that launches a service to do a web search in the background and I would like the main activity to get an intent when the search is done.
In my main activity , I defined a BroadcastReceiver and an Intent Filter to listen to the "end of search" intent:
public class AgeRage extends Activity {
// Listener to all results from background processes
BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ImageSearchService.SEARCH_RESULT_ACTION)) {
0);
Toast.makeText(context,"Got " + i + "results", Toast.LENGTH_SHORT).show();
}
else Toast.makeText(context,"unknown intent", Toast.LENGTH_SHORT).show();
}
};
IntentFilter receiverFilter = new IntentFilter ();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Register to image search service messages
receiverFilter.addAction(ImageSearchService.SEARCH_RESULT_ACTION);
registerReceiver(receiver,receiverFilter);
...
In the service , I do the search and when it is done , I send an Intent:
public class ImageSearchService extends IntentService {
...
protected void onHandleIntent (Intent intent) {
... doing search ...
Intent i = new Intent (this,AgeRage.class);
i.setAction (SEARCH_RESULT_ACTION);
i.putExtra(SEARCH_STATUS, (searchStatus ==SearchStatus.DONE) ? true:false);
i.putExtra (SEARCH_RESULT_NUM, totalResultNum);
i.putExtra (SEARCH_ID, searchID);
sendBroadcast (i,null);
}
But, the main activity doesn't get the Intent. I know that the sendBroadcast is being called and the the receiver's OnReceive is not (checked with a debugger).
I assume that since I create the filter dynamically , I do not need to define a filter in the manifest file.
Am I doing something wrong ?
Thanks
Isaac
Ok. Well I just checked mine and we are doing it the same way, however ...
ImageSearchService.SEARCH_RESULT_ACTION
Try doing com.yourpackagename.ImageSearchSrvice.SEARCH_RESULT_ACTION
where SEARCH_RESULT_ACTION is a public static string variable. See if that helps.
I think it must be the naming of the ACTION. Also note that you might want to run tru the breakpoints and just check log. do intent.getAction() and print this out rather than checking inside the if statement. Just always print it out and see. Don't need to break inside a broacast receiver it will crash after a while.

Categories

Resources