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

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.

Related

How can I auto install programmatically app without start Intent.FLAG_ACTIVITY_NEW_TASK

In fact, I want to be noticed when the program is downloaded without the user having to install their own apps (Install without show permissions activity).
Now I use the following code, and I want to change this code to answer my question.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
The following image is displayed after downloading the app from my server and i dont want to show

how to change install an update dialog message text

in my app there is a new upgrade
I download my new app version to the sd card and open the apk file by
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(oFile), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
oActivity.startActivity(intent);
code block.
i want to change message on the dialog
the image
You're calling exactly that one Activity with your Intent, that does the work. This particular Activity has the particular layout shown in the image. You can have an Activity that starts with the same Intent and that looks different. Nevertheless, the new Activity wouldn't do the work necessary to install the apk-file.
It's all about taking care, that no App can bypass the rights handling and needs to get rights granted by the user and nobody else (especially no App)
In short: No, not possible.

Android: Launch music player service from application

I know that it is possible to launch the music player using an intent using either of the follow:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
or
Intent intent = new Intent(MediaStore.CATEGORY_APP_MUSIC);
startActivity(intent);
However is it possible to start the default music player as a SERVICE rather than an activity? Moreover, is it possible to send actions to that service once it has been created?
However is it possible to start the default music player as a SERVICE rather than an activity?
No, in part because there is no requirement for the user's chosen music player to even have a service. Moreover, the ACTION_VIEW Intent action is only generally supported by activities.
Moreover, is it possible to send actions to that service once it has been created?
Not generally.
There thousands of "music player" apps for Android, any of which can be the "default" for a given user and device. You are welcome to ask each and every one of them if they offer some sort of command-based interaction with some sort of music-playing Service to allow third-party apps to control their player. Some might. Most won't.

Controlling android music player by my own application

I want to write some application to control android music player :)
For example when i shake phone -> player should change music next one. Is it possible without rooting my phone?
I think it is possible, here is a snippet for a performing playback through Intent.
Intent intent = new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER);
startActivity(intent);
or
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Source: Android launching music player using intent
You have to check if there are more Intents you can use by googleing (loading a playlist, etc.).
To control any 3rd party application it first have to be willing to let you to. It is usually done by exposing public API of any sort, so other app would know how to do that. If music player of your choice offers that, then "yes" is the answer. If it does not, then usually it means "no", and rooting is not necessarily a magical solution either. If there's no API or any other communication channel exposed (even non publicly) then achieving your goal would be tricky.

Launching browser on Ice Cream Sandwich

I have a program that I have made for Android 1.6 and up and I have been doing tests to ensure that the program works fine with the new Ice Cream Sandwich (Android 4).
Everything on the app works fine except that when a certain task has been performed by the user it is supposed to automatically launch the android browser. However for some reason it seems to load it up in the background and keeps my app shown which is not what I want it to do.
On every other version of android when I execute the code to launch the browser the browser comes to the top of the screen therefore causing my app to be in the background which is how I wanted it to work.
Below is the code that I have to launch the browser
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(companyURL));
startActivity(intent);
The companyURL is a variable that I am using to parse the url to the browser.
Thanks for any help you can provide.
UPDATE
I have just discovered that if the browser is not currently running (i.e. not been loaded previously) when my app starts the browser it brings it to the front. However, once the browser has been previously loaded, when my app loads it up again, it loads it in the background.
Please try this it is working on ICS for me.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(companyURL));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Typically you don't need the CATEGORY_BROWSABLE category. Try the following instead:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(companyURL));
startActivity(intent);
In fact, the documentation seems to suggest CATEGORY_BROWSABLE is intended to be used in the opposite direction (browser to your app):
Activities that can be safely invoked from a browser must support this category. For example, if the user is viewing a web page or an e-mail and clicks on a link in the text, the Intent generated execute that link will require the BROWSABLE category, so that only activities supporting this category will be considered as possible actions.
http://developer.android.com/reference/android/content/Intent.html#CATEGORY_BROWSABLE
Try adding FLAG_ACTIVITY_BROUGHT_TO_FRONT flag to the intent.
I'm using following code and its working fine with me even when browser is already running in the background.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(intent);

Categories

Resources