Android N announced multi-window drag and drop feature, where we can drag and drop objects between activities.
This is the video of Google-IO'16 where they show the demo (9:56).
Do we have to do anything special to enable this feature in our app or we normally listen for Drop events (Assuming that I only want people to drop into my app from other apps ?
Can anyone give a link to the code sample for this ?
Do we have to do anything special to enable this feature in our app or we normally listen for Drop events
Assuming that you are using setOnDragListener(), your app will receive drop events regardless of origin (from within your app or from another app).
Note that you will want to call requestDragAndDropPermissions() in your ACTION_DROP handling, so that you have rights to any content referenced in the DragEvent. That is not necessary for in-app drop events, and it probably is not needed for simple text drop events between apps, but it becomes important for drag-and-drop of content represented by Uri values.
Can anyone give a link to the code sample for this ?
This project has a pair of app modules. drag/ implements an activity that allows you to drag a photo from an ImageView via a long-click gesture. drop/ implements an activity that accepts the dragged image. The image is shared via a FileProvider.
Related
I am developing an Android Application and need to log my users "journey" through the application.
The events I wish to log include all user interaction events such as when the user clicks on a button etc, and also each Activity and/or Fragment visited.
I know I can litter my code with my logging logic however there are a number of downsides to this such as:-
using autoLink "web" and MovementMethod to allow the user to click on
a web url within a displayed TextView means I have nowhere to add my
logging code unless I use Spannables or a custom textView.
Developer human error will result in logging incorrect details or
missing logging altogether.
What I would like is a single point within the Android framework where I could intercept all UI events and Activity transitions.
I do not wish to create custom widgets to add my logging code.
Is it possible to place my logging code in one Android "hook" to allow me identify which widget was clicked in which Activity/Fragment?
Is it possible to place my logging code in one Android "hook" to allow me identify which widget was clicked in which Activity/Fragment?
No, sorry. Besides, that would be woefully insufficient:
There are many more UI events than just "clicks" (long-press, swipe, other single-touch and multi-touch gestures, key events)
Knowing a widget alone is insufficient, as your TextView scenario illustrates
Is that possible?
I'm developing a service for disabled people. They can define voice commands and the service can detect the commands and execute them. Like when the user says "scroll down", The service (which is in fact a background process) takes control of screen and scrolls down (regardless of what application is on foreground), or touches a specific position and so forth. I wonder if this is possible in an android device? If not, what about a rooted device? (i.e the service has the root permissions). I know that getting voice input and processing it is possible. My question is about doing actions like touch (Action_Down) or scroll the user interface on behalf of a user.
Note that I don't have access to whatever application is running! In fact my service doesn't know about the application that is running on foreground. It might be a social media app or a messaging app or a game or whatever else! So in fact my service must be capable of defining input events like touch, swipe, scroll etc.
Thanks in advance!
Yes, that is possible.
For example, ListView has two methods for programmatic scroll:
listView.setSelection(id); //For instant scroll
listView.smoothScrollToPosition(id); // For smooth scroll
For an example of how to use voice triggered actions - check this answer out
For an example of how to inject events programmatically - check this link out
I try to do a service that will recognize the movement (+ longclick move up) to associate an event.
However, I need this service also works when another application is launched.
At the moment I create a service that gives me a transparent LinearLayout.
I can well recover movement, BUT I can not use the current application below.
Can not click through the layout. I wish, however, that this is possible and that my service detects this movement only.
EX: on Android kitkatt there now has a fullscreen mode and during a slide back down on windowing with the appearance of the taskbar, and the application below have not impacted.
Have you any ideas ?
Thanks.
I wish, however, that this is possible and that my service detects this movement only.
That is not possible from an SDK app on Android 4.0+. Either you receive the touch events or the underlying app receives the touch events, not both. Otherwise, this would represent a security flaw known as tapjacking.
I am using an Android Stick (http://www.geekbuying.com/item/Uhost-2-Dual-Core-TV-Box-Mini-PC-Android-4-0-4-RK3066-Cortex-A9-1-6GHZ-1GB-RAM-4G-ROM-with-Bluetooth-WIFI-Skype-XBMC---Black-312467.html) for building an application. The application uses an attached USB webcam for some of it's functionality. Additionally, I connect a mouse to this device which the user can use to navigate through various pages in the application. A left/right movement of the mouse results in navigation to previous/next page.
While the mouse works with the Android device, I additionally require to reset the position of the mouse to the center after every single interaction with the user. Is it possible to set the mouse position using software in Android? I am using View.OnGenericMotionListener to capture the mouse movement.
Currently, I also require to perform a primary mouse button click to bring the mouse in focus inside the application. I want to remove this requirement by either generating the primary mouse button click in software, or otherwise bring the application in software by some other means.
I have been unable to find any APIs to get the above to work. Any help on these would be greatly useful.
Just in case I need to write some sort of drivers to get this thing working, any help in this direction would also be useful.
Any workarounds around this problem, while still using the mouse, could also prove useful.
Mouse event is managed by the system framework. You cannot control it on Java side.
On the adb shell you can open /dev/input/uevent device to write mouse events include
relative movement
click action
absolute position (you might want this)
However, you cannot do it as a normal application, unless you do it on a rooted device, or you can use adb shell to start a daemon service in the background to perform the event writing for your application.
I additionally require to reset the position of the mouse to the center after every single interaction with the user.
This is now possible with the pointer capture API in Android 8.0+ (released August 2017). Summary:
To request pointer capture, call the requestPointerCapture() method on the view.
Once the request to capture the pointer is successful, Android calls onPointerCaptureChange(true), and starts delivering the mouse events.
Your focused view can handle the events by performing one of the following tasks:
If you're using a custom view, override onCapturedPointerEvent(MotionEvent).
Otherwise, register an OnCapturedPointerListener.
The view in your app can release the pointer capture by calling releasePointerCapture().
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