Select Chromecast media route programmatically - android

I want to start chromecast routing automatically and not when the user presses the button. Does anyone know how i can simulate in any way that the user pressed the media route button? I have looked through the different classes and not found anything.
I am aware that this is not how Google intends developers to use it, and my application is only functioning as a proof of concept.
If anyone knows another way to achieve the same thing (The casting starts when the app starts, if the user has enabled it in the options menu) - let me know!

You can follow the same steps as usual (get a hold of MediaRouter instance, set a selector, register a callback, etc) but then you need to keep a list of discovered routes in your application (as they are discovered by MediaRouter; you will get a call back via onRouteAdded(()). You need to do the bookkeeping as well (via onRouteRemoved() callback). Now that you have a list of routes, you can programmatically decide which one is the one you want to use and again do as usual (same stuff that you would do when you get a callback via onRouteSelected()) except that you need to call MediaRouter.selectRoute(your_selected_route) yourself to tell the framework about it. For the first part, you can take a look at this sample.

So what I discovered was that I couldn't make a check for routes in the beginning of the program because the MediaRouter hadn't discovered them yet. (I.e the call to getRoutes returned only the default route...) In my program, it was enough to start a thread that sleeps for three seconds and then calls selects any available route:
if(mMediaRouter.getRoutes().size() >= 1) {
mMediaRouter.selectRoute(mMediaRouter.getRoutes().get(1));
}
If I needed a more persistent solution, I'd do as Ali Naddaf suggested.

Related

Android VoiceInteraction and Assist API

I've just read about the Android APIs called Assist and VoiceInteraction.
What I'm trying to achieve is an app like NowOnTap. For this, I need an access to the screen's content before the user long presses the home button.
First, I tried using a normal activity with the android.intent.action.ASSIST action.
Digging more into this, I found out that in order to access a screenshot before opening the apps, I need to implement VoiceInteractionSession and its methods onCreateContentView and onHandleScreenshot.
I wasn't able to create UI by using onCreateContentView and, according to my logs, it doesn't even gets called. Anyone with experience using this APIs?

Initiate a private phone call for both side in Android app

I am building an Android app and want to initiate an anonymous phone call for both caller and receiver.
For example:
User A press 'call User B' button, and then initiate an anonymous phone call to User B. The tricky point is that both User A and B don't know each other's phone number and after the conversation, there is no record left and privacy is protected.
I don't know if native Android can do this. Could anyone give me some clues about this? Thank you very much!
According to the platform source-code there is NO WAY to place a call without the knowledge of the user. The best thing you can do is to make the call automatically but the user will see a dialog saying: "Calling XXXXXXXX" and he will have the chance to cancel it.
Even if you make your own dialer application you will have to sign it with the system key and place it in the system/apps folder in order to get the required permissions for that kind of things.
As for the call log, I don't know if you can make the call not to appear in it in the first place but I think (not sure though) that you can find it and deleted afterwards. Android informs other applications of call actions via Intents so it is relative easy to detect when a call ended and then query the call log.
Hope this helps...

Custom dialler for Internet Calls (Android)

I'm trying to get an idea of what's possible and what isn't in terms of using a custom dialler app for internet calls.
The idea is that the standard Android dialler be used when no internet connection is available, but use a custom-written VOIP dialler / caller app whenever an internet connection is available.
I see that in the Android call settings you can set it to use Internet calling whenever a connection is available. How does this work? Does this simply tell the native dialler app to use internet calling, or is there actually a specific Intent or something that gets fired when an internet call is made so that I can open my custom SIP app?
And also, is the 'standard phone app' icon always linked to the standard phone app, or can you override this phone icon to open your custom VOIP app when a connection is present?
So basically, is there a way to seamlessly and automatically switch between the standard dialler and the custom SIP dialler based on whether or not the phone is connected to the internet?
If not, is this something that could be done by customizing Android?
Thanks,
There are four possible ways of doing what you want that I know of:
1. Replace the Android Dialer
This is hard and a lot of work. The Android Dialer (last time I checked anyway) WAS the telephony stack in Android. So to replace it you have to replace the complete telephony stack (including any public API) i.e. handle all cellular (and now sip) calls in and out of the device. Also the only way to replace it is to root the device as it can't be replaced normally.
2. Provide your own Dialer that is separate to the main dialer.
This has it's advantages that you will never get into "trouble" with anything else.
3. Hook into the outbound call API (ACTION_NEW_OUTGOING_CALL)
This is something that is pretty cool and I haven't seen any other OS allow you to do. Basically you can trap when either the normal dialer starts to dial a number (or when another application starts to dial a number as well) and you can either allow it through, modify it or cancel it. Behavior I've seen from sip clients is that they will cancel the call and put up a selection screen prompting where you want to send the call (sip, cellular or something else).
Here is an example of it's use.
The downsides are:
You can be fighting with other applications to which gets first go. There is a 'priority' setup, but all I've seen is everybody wants to be number one.
On some Android devices where the OEM providers that own Dialer, they don't always fire it!!!
4. Detect when the dialer is shown and show your own dialer in front of it.
This works and does allow you to provide a nicer more integrated feel as you can provide call type selection within the dialer, as well as other custom number lookups but that can be a little tricky to do on some devices.
I would suggest 3 to begin with as it's pretty easy to do and you can get something up going pretty fast. In code that I have worked on, we have done 2, 3 and 4 and also looked into 1.

Any listener for system preferences in Android

I want to capture event when an user try to go into the preferences screen, so I can ask password for it. The reason why I try this, I am developing app for the disabled. I don't want them to touch system settings directly, just the permitted helper.
Is there any event listener or receiver for this?
Thanks in advance.
I don't think there is anything in the public APIs that will allow you to do this. Device Admin is probably the closest thing, but I don't think it does this exactly.
If you wish to implement this (and be certain that it will be effective) you'd have to modify the OS slightly on your devices.
One possibility that might work and is within the APIs is to create a replacement home screen that does not show the usual items in the menu. If you were to go this route you could "lock" the into your activity and simply provide them no way to go to the settings except with a password or something. This would be a lot of work though, and would require the user to set your application as their default home screen. And even with this on the newer devices you may run into the trouble because there is a settings button inside the notification pull down, which I don't think there is a way to block, even with a replacement homescreen.

Simulating mouse clicks from service

I am looking forums for two days now and can't find the answer. I am new to android and i have a problem. I need to have a small server service in backround (which i have) that gets coordinates for example. With that coordinates i must simulate (make) a click on the active activity...
It should be service for controling the android from the computer. The computer client aplication sends some information like pressed key or mouse click and the service gets it and performs action on active activity.
Is there any way to do that , some example or something ? Thank you
This is not possible due to obvious security risks.
If you're looking to test your activity, have a look at TouchUtils:
http://developer.android.com/reference/android/test/TouchUtils.html

Categories

Resources