android: put call phone in background when is answered - android

I'm developing an Android application that have a button to init a call phone when is clicked.
I want to detect when the call phone is answered and automatically put the native phone application in background and show my application again. Meanwhile, the call phone runs in background.
The result has to look like when you click the back button of the smartphone or if you open manually my application while the call phone is in progress. But this should be done automatically without pressing any buttons.
I know that I have call listeners to do something when the state of call is ringing, offhook or idle, but the problem is putting the call application in background from my application.
Sequence:
user clicks button in my app to launch native phone application (Android).
the phone call starts (call state: ringing).
the phone call is off hook (call state: Off-hook).
automatically, my application detects it and puts the native phone app in background and puts my application in foreground.
Is it possible and how I can do it?

Create a background service and implement BroadcastReceivers to listen the call state triggers.

you can put your app in the foreground after the call was answered using Activity start.
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(
getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
now the problem is that the started activity will be a NEW activity (It will clear all previous activites - without these flags it won't return back from the call screen).
i don't know how can I actually return to already working activity in the background.

Related

How to prevent minimized app to stay on foreground after the VoIP call ended?

I'm trying to develop a VoIP call application on Android and there is a problem which I cannot find any solution. Also, I don't know how to search the problem, so let me explain the scenario:
User sends the app to background by pressing the home button (minimize the app). Then when he/she gets a call, my call screen activity comes up. It is ok till here. My problem is the last activity comes to foreground when the call ends, but as the user sent the app to background before the call received he/she wants the app to stay in background after the call ended.
How can I make the application stay in the background after the call ends?
Before calling finish() when your application's Activity ends, start the HOME screen:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

How to stop/pause an activity in watch from mobile?

I am currently starting an activity in watch from mobile by clicking a button. I am using wearable listener service to do it. Once the activity is started, the user performs gestures which are recognized and sent to mobile. So at some point in time, I want the user to click a button in mobile to close/pause this activity in watch. How can I do it? Should I destroy it or pause it? What should be my approach? Please advise
When you receive the message telling to close app in watch from phone,you can cancel all running work and close all activities in watch app or call System.exit(0).

User-placed phone call from app sends app to background

My app is meant to be used while on the phone and it has pre-programmed buttons for placing calls to key people.
The problem is when a call is initiated, the phone goes to foreground rendering app unavailable. How to continue phone call but have app come back to foreground automatically ?
So far I have a phone state listener which is working fine, and I use it to fire an intent to my main activity when phone ringing is detected like this,
Intent i = new Intent(getApplicationContext(), MainActivity.class);
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
Its not clear what is happening with this. It seems like MainActivity is getting restarted ( or resumed ?), several times actually, but foreground stays unchanged in the phone activity.

android hidden app strategy

I'm trying to create an app "hidden" from applications list.
The way i though the user will start the app is through a Receiver listening for NEW_OUTGOING_CALL and intercept a particular number dialed.
The problem is that on new Android versions, this receiver will never be activated if the app never start once. (Starting the application from a BroadCastReceiver (NEW_OUTGOING_CALL doesn't always work)).
I can't figure out a workaround for this problem: the app launcher is totally hidden so the user cannot never launch the app, and the receiver would never be activated if the app will never start.
Is there any other strategy or workaround for hide and launch the app with some kind of secret action?
Create a activity with manifest file pointing it as the the Launcher activity and make it transparent and call its finish method in onCreate. User clicking on that icon will have no idea that the activity is opened. But why don't you show the About application kind of screen in the launcher activity?

How to Resume Previous running application from An Application in Android?

Give me a little guidance:
as My Application is running with Broadcast Receiver and when ever my application in Background and any incoming event comes it triggers the my Application.
Now we want as We are listening or playing some video file or browsing on Android Phone
and with incoming event occur and my application launch(already running in Background),
If i will ignore the event , we want to go back previous running task (Like browsing, playing
video file application), How we can achieve?
Now I am using The store the running application package and Activity info before triggering the Event , and after finishing using this info we resuming the Activity and
It working fine but Only with Gallery Application Playing of Vedio file is not fine , It Crashes the Application and relaunch the Gallery App.
Please give me some Valuable points to make it up?
On calling finish, Previous application resume(Playing of Media file) but when next time
on getting broadcast intent and try to launch the Activity , The Activity is not launching
and application itself crashing.
After a long back I got solution of my problem and we need only use to this api
moveTaskToBack(true);
and automatically resumes the previous running task(like browser, media application or any thing)
Have you tried to start you activity by
startActivityForResult(Intent intent)
When you call finish() in the Activity you should return the the previous one, I am not sure if this will function over between Activity running in different applications. Give it a try :D

Categories

Resources