Control the device using Android Application - keyevent

I am developing an application to control the android device from one android device like control the device via input keyevent. If I want to press menu button from my application on one device will open the menu button on another device which to be controlled.
I thought to transfer some data while clicking on button on device. According to the data received from sender, it will perform the action. Please guide me to do this.
What are the ways available to transfer data between two devices using API's?
UPDATE:
I have used socket to send data from one device to another device. Receiver side application is running on back ground and receiving the data which is sent by controller. According to that data, receiver will perform the action. The action is like to pressing back button on that device, if the receiving data is "back", to pressing menu button on receiver device, if receiving data is "menu"
Now my question is how to do that activities ( pressing buttons on real device ) from application?
Solution:
I used to navigate device from keyevents. Sample code is below:
try { Instrumentation m_Instrumentation = new Instrumentation();
m_Instrumentation.sendKeyDownUpSync(keyCode);
} catch (Exception e) {
Log.d(TAG, "Permission denied!!!");
}
I'm building my app as system application by putting source into AOSP. I used user-permission to access it as
<uses-permission android:name="android.permission.INJECT_EVENTS" />
Even though, I am getting permission denied to trigger keyevents. Logcat is below:
D/ServerService( 668): down
D/ServerService( 668): down
D/ServerService( 668): down Button is pressed
D/ServerService( 668): down is pressed
W/InputDispatcher( 187): Permission denied: injecting event from pid 668 uid 10036 to window Window{41524818 com.android.launcher/com.android.launcher2.Launcher paused=false} owned by uid 10023
W/WindowManager( 187): Input event injection permission denied.
D/ServerService( 668): Permission denied!!!
Question:
How to solve the above "Permission denied" issue. I have referred the link. But, It couldn't even works! remains the same issue. If anyone know the way to solve it , share.
Otherwise, If you know any other way to navigate(control) device, let me know.

Related

Xamarin.Forms UI not responding

I'm working on a Xamarin.Forms app using the Prism library. The app has a phone component to it with integration to CallKit and a SIP library. When the device is locked, a call can be received, which results in the native phone UI for iOS. User can answer the call and hangup. Within the app, there is a Xamarin.Forms page to handle calls. There are events from the iOS service that deals with the calls to interact with the "shared project". The issue that I am running in to is that when the user unlocks the device and returns to the app, the UI is non-responsive.
Scenario:
User starts app and logs in.
User locks device
Incoming call received
User answers call
Behind the scenes (i.e. native phone UI), the call service communicates with the "shared project" to display a Call Screen in the app. Since the phone is locked, the user will not see this now.
User hangs up.
When user hangs up, the call service communicates with the "shared project" that the call has been terminated and to return to the previous screen.
User then unlocks the screen
App is on same screen as when user locked device, but UI is not responsive.
To navigate to the call page, I am doing:
await NavigationService.NavigateAsync(targetPage, null, useModalNavigation: null, animated: animated);
and to return to previous page:
await NavigationService.GoBackAsync(animated: false, parameters: parameters);
NavigationService is of type INavigationService from Prism.
The essential question is: what would make the navigation appear to work, but result in a non-responsive UI? I've found in the past that I need to do the navigation on the main thread. Is there anything else I need to look for?
What I understood that you are looking for a method just like the OnAppearing method of forms page.
You need to implement interface INavigatedAware to your ViewModel. By doing this, 2 methods will be added to your ViewModel "NavigatedTo" and "NavigatedFrom". You need to put your logic into the "NavigatedTo" method. This method will be triggered whenever that particular page will appear on the screen.

App close event in Ionic Windows 8.1 App?

I'm building a Windows 8.1 App using Ionic 3. In the app, the user would have to type in a lot of stuff. I want to avoid accidental closure of the app by clicking on 'X' button at the top right corner or by Alt+F4. When the user tries to close the app, is there a way to prevent the default behaviour of closing the app and instead ask a confirmation?
You must override the onbackbutton event to do this.
document.addEventListener('backbutton', function (evt) {
/* BackButton pressed: do nothing */
return;
}, false);
Do NOT use the method shown on that page to exit the app:
throw new Error('Exit'); // This will suspend the app BUT the store will reject it
If you do this to exit your app, it will be rejected by the Microsoft store. To exit the app, remove the event listener and let the backbutton event suspend the app normally.
There's no special event to indicate that the user has closed an app.
App Lifecycle docs for Windows Store Apps.
https://learn.microsoft.com/en-us/previous-versions/windows/apps/hh464925(v=win.10)?redirectedfrom=MSDN#app-close
When the user closes the app or moves the app to background, it enters into a Suspended State. Windows recommends saving user state when the app enters such a state. You can save data in that state thereby achieving the overall goal.

Open Apple Maps by tapping on a WKInterfaceMap in a dynamic notification

My Watch app receives push notifications containing location information and I use that info to show a WKInterfaceMap.
However, when I tap on the map in the notification dynamic interface, my app is opened instead of the Maps app.
I found this forum post stating:
There is no url to call at this time. The user tapping on a WKInterfaceMap object is the only way to launch the Maps app from yours.
Does anyone know why this does not work with WKInterfaceMap objects in a notification?
Since notifications are not interactive, it's not possible to trigger any object interaction in a dynamic notification. Tapping anywhere in the notification area will always launch your watch app.
This is briefly mentioned in the App Programming Guide, under Designing Your Dynamic Interface:
Tapping your notification interface launches the app, so notification interfaces should not contain interactive controls.

how to track sent message event in windows phone?

Is there a way in windows phone to track sent message event? i mean to say that whenever a message is sent then a function of my application execute
all i want is to execute a function whenever sent message button of windows phone is clicked?
If you open the message launcher (I don't remember the exact name), it'll open this screen and you have the event (something like application deactivated) and once the user sends the message, the screen should close and come back to your app (again another event is available at that point, activated).
So you'll have to play with the events to do something you like, IIRC there is no call back when the message button is clicked.
Here's a link with the lifecycle of apps
There is no API that notifies you if a message was sent (at least no open API). A similar question was asked here.

Scanning notification through WIA

I've registered to receive WIA notifications for all devices through RegisterEventCallbackInterface for WIA_EVENT_DEVICE_CONNECTED and WIA_EVENT_SCAN_IMAGE events. However I only receive notifications when scanner device is plugged in - I don't receive notification when I scan (for example with mspaint which uses WIA). Am I supposed to receive scanning notifications from applications or only when Scan button is pressed on a device? (I haven't tried the latter since I use a multifunction printer without Scan button). Is there any other way to be notified about successful scans through WIA? Thank you.
The notification API will just tell you if the button has been pushed. You can register a temporary or permanent (i.e launch an app) handler. If you're trying to scan you need to use Item.Transfer() or CommonDialog.ShowTransfer() from device.Items[1].

Resources