Start and Stop an external app from my own app in Android - android

My app starts others apps (upon user request) using this simple code:
Intent LaunchApp = getPackageManager().getLaunchIntentForPackage("the.external.app.package");
startActivity( LaunchApp );
Is there a way to finish or close that app?
I have tried with ActivityManager.killBackgroundProcesses() and with android.os.Process.sendSignal(pid, android.os.Process.SIGNAL_KILL) but no success.
The idea is to do something like this:
If the app connects to the car bluetooth then it starts the music player automatically. Once the bluetooth is disconnected it should close the music player.
Thanks

You can close activity without killing process.
Use startActivityForResult() instead startActivity()
startActivityForResult( LaunchApp, 100 );// reques code = 100
Close activity by request code when you need that
finishActivity( 100 );

Related

How to Open my App during a call?

I want my app to open whenever the user makes a call. I am able to know that call has started but cant open my app. Is there any way i can do that.
Thanks in advance
When you know that a call has started, use your package name / class directly, for example to create a new intent to call the twidroid program you'd use the followinglink text:
Intent intent = new Intent("com.twidroid.SendTweet");
You'd probably want to put a try/catch around for a ActivityNotFoundException for when the application is not installed.

Start Google Now on Music Recognition

Is there a way to automatically start Google Now on Music Recognition? I'd need it to create a DashClock extension that start Music Recognizing...
As far as I speak, I can start package com.google.android.googlequicksearchbox successfully but I cannot start voice input... I would not use startActivity for result since I would not need a result, I would really just start Google Now voice recognition feature, is there a way to do it programmatically?
Otherwise, to simply launch Google Now Song Recognition service (without having to tap on "Listen to Music", to be clear), you can create an Intent with the string
"com.google.android.googlequicksearchbox.MUSIC_SEARCH";
that would launch directly the proper interface.
I just found a way to achieve my goal:
Intent intent = new Intent();
intent.setClassName("com.google.android.googlequicksearchbox","com.google.android.googlequicksearchbox.VoiceSearchActivity");
starting this intent will bring up voice search window.

Android - how to open an audio-stream url with an external app?

I want to give the user the choice of opening an audio stream url with an audio player that he already have installed.
The following code works as so far that the user getting a list of installed audio apps and can choose between then.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(stream.getAudio()), "audio/*");
startActivity(intent);
But it will open an intent that lives inside my app only. Therefor the playback will stop if the user closes my app. How can I change the behaviour so that not an new activity is started but the whole app is launched and is detached from my app.
I guess it's because the audio player is opened in the same task stack of your app.
Try Intent.FLAG_ACTIVITY_NEW_TASK to start it as a new task, like:
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
See Tasks and Back Stack to learn more.

Android : Launch Skype to be in background

I hope this is just a temporary problem and Skype allows an autostart feature.
I need to launch Skype so that it can receive Skype calls and video calls, and then launch my app. I work with the elderly s simplicity is at a premium. My app runs continuously.
The following code seems to achieve this goal in a BOOT BroadcastReceiver.
PackageManager pmi = context.getPackageManager();
String packageName ="com.skype.raider";
context.startActivity(pmi.getLaunchIntentForPackage(packageName));
Log.d("ANDRO_ASYNC",String.format("should launch Skype"));
Intent intent1 = new Intent(context,MyApp.class);
intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Bundle bundle = new Bundle();
bundle.putInt("FromBoot",1);
intent1.putExtras(bundle);
try{ // hoping to schedule the start to after Skype has finished
Thread.sleep(20000);
}catch(InterruptedException ex){
Log.d("ANDRO_ASYNC",String.format("error in delay loop"));
}
context.startActivity(intent1);
This launches Skype and waits 20s to get sorted out before launching my app. My app ends up on the screen (desired effect).
However, it has a tiny problem for most people, but a big one for me. After the first Skype call the Blue welcome screen of Skype stays up, and the user has to press back button. Effectively this makes ending a Skype call different depending on whether it is the first or subsequent calls.
Questions.
Can I close Skype from my app?
Can I detect that Skype is finished teh call from my app?

accessing one app from another app

Can someone explain me how to control one application from another application? I'm running a music player in an app1 using service class. And I want to stop that music player from another app.,i.e app2. But, I'm fallin short o the concept.
Depends what you need to do.
Opening another activity (or sending messages) is by using Intents:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
// ...
startActivity(intent);
Starting service is by using startService()
What you are trying to do can also be done using Intent broadcasts but only if your target app supports and listens to specific actions on the broadcast. You need to see if there is such an ACTION supported.
I'd like to continue this question a bit.
In my case, I'm developing the target app and I need to implement few simple procedure calls for the main app. Basically 'start', 'stop' and 'sendData'. As I wrote, I'm developing the target app so I can support whatever I want. Which would you say is the easiest way to handle.
The whole situation a bit more explained. Main app would like my app to start it's work, and if needed they'll request that I turn myself off and when the main app is closing it would request me to send my data forward.
I'm quite new to android development, so code snippets are preferable. Thank you.

Categories

Resources