Sony SmartWatch - Widget window - android

Starting to develop an app these days, i'm stuck trying to open a "window" when the screen is touched in the widget.
In Code Examples (sdk), we can see this in the Event Widget, when you click in the screen, a "window" is opened, and you can see the events there.
I follow the code to see how can i do this:
in NotificationWidgetExtension : SmartExtensionUtils : onTouch event
Intent intent = new Intent(Widget.Intents.WIDGET_ENTER_NEXT_LEVEL_INTENT);
sendToHostApp(intent);
In WidgetExtension
protected void sendToHostApp(final Intent intent) {
intent.putExtra(Widget.Intents.EXTRA_AEA_PACKAGE_NAME, mContext.getPackageName());
intent.setPackage(mHostAppPackageName);
mContext.sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);
}
Trying to replicate but i'm not being successful. Is there any place i can read about it, or someone can help me on this?

I think you are looking at three different APIs - the Widget API, the Notification API and the Control API.
The onTouch code that you reference is a part of the utility classes of the SDK, and is there to help you if you have made an extension that have both implemented the Notification API and the Widget API. When in the Widget view on the watch, and you have overridden the NotificationWidgetExtension class, the onTouch event will be delivered to the mentioned method. It will basically show the first available (and not read) notification.
You mention "window" etc, and I am guessing that you want to create an application on the SmartWatch. This is done through the Control API. Take a look at the SampleControlExtension contained in the SDK. Check this answer, to get information on how to start a Control extension from your own extension. E.g. if you create a Widget+Control extension, you could start the Control extension in the onTouch method of your Widget.

Related

Flutter: How do I call a function in widget A from widget B when the widgets do not have a parent/child relationship?

I have the following structure for my app, where ChatScreen contains the ChatHeader and the ChatFooter.
---ChatHeader.dart --- MessageDao.dart
ChatScreen.dart ---
---ChatFooter.dart
In the ChatHeader widget, I call another widget called MessageDao.dart. This widget generates the button that the user can press on the ChatHeader widget to play audio.
In the ChatFooter widget, this widget contains a different button that the user can press to record using their mic.
When I play audio using the button from ChatHeader -> MessageDao, this works just fine. However, if I click the button in the ChatFooter widget to start recording while in the middle of playing audio from the first button, this audio doesn't stop playing. It keeps playing while I'm recording. I have a stopPlaying() function in MessageDao that I can use, but I'm not sure how to call a function in widget A from widget B.
Or in other words, how do I call MessageDao.stopPlaying() from inside ChatFooter.dart?
With this type of situation, the ideal solution is to take a page out of React and 'lift the state up'; this means that whatever method is on the child should be lifted to a higher node in the widget tree (e.g. ChatScreen) and then pass the function down to the nodes that use it (ChatHeader and ChatFooter). You could also try leveraging InheritedWidget after 'lifting state up' and avoid sending methods down a chain of widgets.
Now, this is a recurring theme with Flutter apps (and overall declarative frameworks) and is a problem that can have multiple solutions. My suggestion would be that you take a look at different state management options like bloc, provider, mobx, riverpod, rxdart, redux or event_bus_plus just to mention a few. Said libraries will give you the abstractions you need for each use case and help you avoid implementing really complex logic that you might need to solve problems similar to this one by yourself.
Of course, this is an important decision for your project so I suggest you take a good look and choose whatever you feel comfortable with or is similar to something you have worked on before.
Good luck my fellow Flutter developer, choose wisely :P
You can use some event mechanism to notify MessageDao about an event in your app, e.g., AudioRecordingStartedEvent.
On MessageDao you subscribe on the event and stop the playing audio,
On ChatFooter you fire the event.
On pub.dev a lot of libraries that implement EventBus, e.g. event_bus_plus

How to get pop up window in part of phone like the image

I am trying to make my own alarm app and want to have a partial view open up when an alarm activates no matter where in the phone I am at, like the image I am including. Can I please get some tips on how I would do this, do I start an activity through an intent with the alarm manager? Or can I just start a fragment? Also, how do I get it to just be the little window, I prefer that, and do not want to launch a full screen view. Apologies that I do not know much, I don't have anyone else to ask for advice. I am using kotlin, Thank you.
That's just a notification that has a button.
You'll find everything here: https://developer.android.com/training/notify-user/build-notification
To add a Button: https://developer.android.com/training/notify-user/build-notification#Actions
Just a hint: If you change the behaviour of your channel, clear your appdata or choose another id (Or even better: delete your channel via notificationManager if it's not needed anymore). Otherwise the changes will not be applied.

Accessibility Event Issue

I want to make my own accessibility service using the API's, but when
some buttons are clicked, no event of type VIEW_CLICKED is logged.
In accessibility.xml,
I set android:accessibilityFlags="flagDefault|flagIncludeNotImportantViews
I'm not sure Why when I click the Accept and Continue button in Chrome (as part of the first run activity), no click event is logged.
Any help would be greatly appreciated.
You need to specify android:accessibilityEventTypes. To intercept clicks you need to use typeViewClicked option.
Something like that:
android:accessibilityEventTypes="typeViewClicked"
For more information you can check Android documentation.

Background app to listen to Drag gestures

I need to register a broadcast receiver that will tell me any kind of Drag events throughout the system. My app will run at background and perform any task if any kind of Drag event happens even any other app is running in the foreground. Is it possible? Any idea on how can I do it?
Updates: Do not think I'm going to make keylogger. My app will be visible but will run in background. And all I want is simply to detect Drag events (drag to left, drag to right, drag to up and drag to down).
I'll accept any answer if you can tell me about how can I display 4 buttons those are permant, on top of any other apps because this can also serve me what I want.
Your app can run without a "normal" UI by running as a Service, as per your link, but I think the code you linked may be slightly out of date.
Remember that your service must run in the foreground - the code is supplied there in your link, but not explicitly called. Without running in the foreground, the system could well stop your app rather than running it in the background.
When I created a task switcher using such overlays, I found it was necessary to use a TYPE_SYSTEM_ALERT rather than TYPE_SYSTEM_OVERLAY.
Android 4.x - System Overlay - Cannot capture touch events
I declare my window parameters without FLAG_WATCH_OUTSIDE_TOUCH.
WindowManager.LayoutParams params =
new WindowManager.LayoutParams(width, height, x, y,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
Your service should also be sure to properly unregister the overlay view from the WindowManager when it ends. Without this, you app will leak memory.
public void onDestroy()
{
super.onDestroy();
if (overlay != null)
{
((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(overlay);
overlay = null;
}
}
I see that this is done in OverlayView.destory() (note the incorrect spelling of that method name - it would be a good idea to use the correct name for that method).
So your real requirement is to be able to pass some input to your app whilst allowing the screen to be dedicated to outputting video.
Have you thought about the following:
detecting tilt or orientation of the device to control direction
having 4 nfc tags, and detecting which of those you are over to change direction (may not give you a quick enough response)
It is also possible to have actions that are selectable directly from notifications, so you could have one or more notification that offer actions to control the direction, and simply allow the notification API to handle the job of appearing in front of the video.
Of course there are apps that manage to overlay their UI in front of other apps. Such an example is Thrutu, though you seem to be pushed for time, and getting such a solution working is not straightforward - see How do I implement a slide-out drawer on the Android's call screen?
I found my answer here. I need to start a service.
The library standout allows you to create floating applications(applications that go over other applications). I used this for a couple android applications I put on the market a while back. It makes creating the floating windows pretty simple. Check it out at:
http://forum.xda-developers.com/showthread.php?t=1688531

how to add an action to copy/pase or listen to copy event on android

Hie!
I'm trying to develop an app that will do one of these 2 options -
whenever a user marks a text in any app (using the regular copy/paste), there will be another option besides copy/cut that will open my app. (preferred)
My app would listen to a copy text event in another app and will show a notification to the user. when they press it, it will open my app.
I haven't found a way to do either of these options.Some claim that I can listen to the copy activity but I couldn't understand how to do it(Android : How to listen to longclick events in any text area in other applications? click-events-in-any-text-area-in-other-application).
I'm not looking for anyone to write the code for me of course, just a pointer to the right direction if this is possible.
Thanks in advance,
Shahar
After short investigation I don't think it is possible. You may look at this guide, but it says copy/paste is implemented using ClipboardManager in Android, which looks like a part of a system. And it doesn't provide any hooks or interfaces to intercept copy/paste events in other app.
Sure you may hack deeper in this mechanismus on rooted device, but this will not work for all users.
Very late response but you can create a custom text selection action, which is an activity with an intent filter with action android.intent.action.PROCESS_TEXT, and whenever a user press on text, a text selection menu appears, your's will be available too,
when the user clicks on your custom text selection action, the activity configures with the android.intent.action.PROCESS_TEXT will be opened for your users.
check this article for implementation steps Custom text selection action

Categories

Resources