Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add click button on widget #6

Closed
huytower opened this issue Nov 16, 2020 · 7 comments
Closed

Add click button on widget #6

huytower opened this issue Nov 16, 2020 · 7 comments
Labels
p:Android Android Home Screen Widgets

Comments

@huytower
Copy link

huytower commented Nov 16, 2020

Hello,

I applied this library success,
I add more feature when using this.

  • Show title & message (done)
  • A button for integrate : Play button (doing)
    Screen Shot 2020-11-16 at 14 17 26

I did not found any document details the method like setOnClickListener() (or setTextViewText()) to apply (Even Ctril+Space does not help me also)
So how I implemented a clicked button success?

Please help me indicate that?

Code lines :
Screen Shot 2020-11-16 at 14 17 54
Screen Shot 2020-11-16 at 14 18 11

[✓] Flutter (Channel stable, 1.22.3, on macOS 11.0.1 20B29, locale en-VN)
• Flutter version 1.22.3 at /Users/huytd/flutter
• Framework revision 8874f21e79 (2 weeks ago), 2020-10-29 14:14:35 -0700
• Engine revision a1440ca392
• Dart version 2.10.3

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/huytd/android-sdk
• Platform android-30, build-tools 30.0.2
• ANDROID_HOME = /Users/huytd/android-sdk
• Java binary at: /Applications/Android
Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.2, Build version 12B45b
• CocoaPods version 1.10.0

[!] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build
1.8.0_242-release-1644-b3-6915495)

[✓] Connected device (1 available)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android
7.1.1 (API 25) (emulator)

@ABausG ABausG added the p:Android Android Home Screen Widgets label Nov 17, 2020
@ABausG
Copy link
Owner

ABausG commented Nov 17, 2020

Currently there is no support for communication from HomeScreenWidgets back to the App. But it is on my list!

@huytower
Copy link
Author

Okay I got it.

@vishaldhaduk4495
Copy link

@ABausG When we expect the click from widget to app?

@jja08111
Copy link

jja08111 commented Mar 6, 2021

Same issue for me. I don't know how to implement a button-click event.

@ABausG
Copy link
Owner

ABausG commented Mar 8, 2021

I'm working on adding this functionality. If everything works it will come in two stages

  1. Detect in the Flutter App if the app was started from a Widget/which part of the widget
  2. Execute Dart Code if part of widget was clicked (I think this will only work on Android as as far as I know iOS does not allow code execution from a Widget without opening the app)

Unfortunately I can't give an estimate on when this will land but it is the feature that is on top of my list.

@ABausG ABausG reopened this Mar 8, 2021
@jja08111
Copy link

jja08111 commented Mar 8, 2021

I've implemented a button-click event by overriding the onReceive function using the code here in the native end.

  1. Add action name to AndroidManifest.xml.
  2. Using setOnClickPendingIntent() with PendingIntent like that.
companion object {
    private const val BUTTON_CLICK_ACTION=  "StartSleepButtonClicked"
}

...

val pendingButtonClickIntent: PendingIntent = Intent(context, HomeWidgetExampleProvider::class.java).let {
    it.action = BUTTON_CLICK_ACTION
    it.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId)
    return@let PendingIntent.getBroadcast(context, widgetId, it, PendingIntent.FLAG_UPDATE_CURRENT)
}
setOnClickPendingIntent(R.id.button, pendingButtonClickIntent)

...

override fun onReceive(context: Context?, intent: Intent) {
        super.onReceive(context, intent)

        if (intent.action == BUTTON_CLICK_ACTION) {

        }
    }

@ABausG
Copy link
Owner

ABausG commented Apr 3, 2021

Version 0.1.2 contains click listeners.
You can now detect if the App was started via clicking on the HomescreenWidget.
On Android you can also execute Dart Code in the Background. For more Info read the updated README

@ABausG ABausG closed this as completed Apr 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p:Android Android Home Screen Widgets
Projects
None yet
Development

No branches or pull requests

4 participants