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?
Related
According to the android documentation (https://developer.android.com/guide/components/activities/background-starts) this shouldn´t even be "possible" anymore. I checked many posts already but they all seem too old or say this isn´t really feasible or easily doable anymore. But still, there are apps doing this today like (StayFree for example). I want to start the activity with a running service that checks data in the background.
What I would like to know or I think is needed:
Permission like display over other apps (Something like ACTION_MANAGE_OVERLAY_PERMISSION)
A service for which is running in the background while the app is not open and starts the activity from the background.
Attention: I want the overlay/activity to be a normal activity and not a system alert window.
I tried many things but I am still mainly a C# Dev so help I would appreciate your help thanks!
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.
I have 2 different applications A and B and I want to create a special animation from B to A, that is when A is opened after B was visible. This means that I need to somehow know the previous app after which my app was opened. I can have different scenarios of going from B to A - using Recent Apps (multitasking) button, using Back button, using Home button (application A is a custom home screen). Are there any ideas how to do this? Some functions in ActivityManager might help, but they have comments in documentation saying not to use them for implementing logic and control flow.
Not sure if this will work across different applications, but how about getCallingActivity() or getCallingPackage()?
If that doesn't work, could you pass along some 'extra' data in the bundle when you launch the intent that indicates the launching application?
I managed to figure out how to implement this, its working for me.
I used this answer, but replaced the ActivityManager.getRunningTasks() with ActivityManager.getRecentTasks() supplying RECENT_WITH_EXCLUDED | RECENT_IGNORE_UNAVAILABLE, and took the component name from baseIntent member of the result. The info at index 1 is the one that was running before the current app was opened, irrelevant of the fact how you get back to your app - back button, home button, recents button or opened from another app.
NOTE: This works when your app is started, like in onResume() but doesn't work when your app is closed (when called in onPause()) because the new task is not yet loaded into the activity manager. So if you need to also know to which app are you going then it might be a bit more complex.
NOTE2: Although the documentation tells not to use the API above for any kind of logic and control flow, I saw that the multitasking/recent app's code is doing exactly the same, so in my opinion it should not be as risky as they write it docs.
NOTE3: Don't forget to follow all the steps in the answer I mentioned above, like adding needed permissions, otherwise you will get exceptions. Being part of the system in my case makes it much easier for me.
Im trying to develope an app which is an Overlay working on top of all aplications in the system, till there I dont have problems.
The issue is that my overlay has to be able to manage some events and others just let them go under it.
Example:
The App has to manage onFling events and do some operations.
The App must not manage onClick events, letting them go to the activity posicionated under its
I have found some information about how to do that, although you need to have root permissions to inject events in the system or another app running on it.
Here you can find further information :
http://www.pocketmagic.net/2012/04/injecting-events-programatically-on-android/#.UReb1KWIes0
http://www.pocketmagic.net/2013/01/programmatically-injecting-events-on-android-part-2/#.UReb3aWIes2
I'm writing an android app just to get familiar with the OS and API. I'd like to show what my app is doing to the user in a seperate screen and not via notifications. The reason is that I'd like to show the user exactly what the app is querying and how long it took etc. I saw an example of this in the superuser app which shows what the app is doing when it is updating itself.
Is there a library to do this?
Is it as simple as just showing a text box and then populating it programatically?
I would have done it so..
Just push state changes to your UI thread and display them there.
You can do that via BroadcastReceiver, which is intended to let background services communicate with UI activities, or LocalBroadcastManager which is simpler version of the previous.
Here on StackOverflow you will find dozens of questions describing how to implement it.