<p dir="auto">while i was working with flutter i came across a situation that i want to access flutter plugin from my native code<br>
example</p>
<blockquote>
<p dir="auto">i set SharedPreferences using flutter code  and i want to access this<br>
prefs from java</p>
</blockquote>
<p dir="auto">i achieved that by reading plugin source code and get SharedPreferences name and how the plugin store keys and every thing worked as expected , but i wonder if there easier way that i can use ?</p>
<h2 dir="auto">Steps to Reproduce</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="dependencies:
  flutter:
    sdk: flutter
  url_launcher: ^4.0.2"><pre class="notranslate"><code class="notranslate">dependencies:
  flutter:
    sdk: flutter
  url_launcher: ^4.0.2
</code></pre></div>
<p dir="auto">Code sample:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="String url = 'https://baomoi.com/tai-dung-binh-cua-hlv-park-hang-seo/r/28958542.epi';
if (await canLaunch(url)) {
    await launch(url, forceWebView: true);
} else {
    print('Could not launch $url');
}"><pre class="notranslate"><code class="notranslate">String url = 'https://baomoi.com/tai-dung-binh-cua-hlv-park-hang-seo/r/28958542.epi';
if (await canLaunch(url)) {
    await launch(url, forceWebView: true);
} else {
    print('Could not launch $url');
}
</code></pre></div>
<p dir="auto">Result : webview did not show</p>
<h2 dir="auto">Logs</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="E/MethodChannel#plugins.flutter.io/url_launcher( 1626): Failed to handle method call
E/MethodChannel#plugins.flutter.io/url_launcher( 1626): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.app.ContextImpl.startActivity(ContextImpl.java:672)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.app.ContextImpl.startActivity(ContextImpl.java:659)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at io.flutter.plugins.urllauncher.UrlLauncherPlugin.onMethodCall(UrlLauncherPlugin.java:61)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.os.MessageQueue.next(MessageQueue.java:323)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.os.Looper.loop(Looper.java:135)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.app.ActivityThread.main(ActivityThread.java:5417)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/flutter ( 1626): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter ( 1626): PlatformException(error, Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?, null)
E/flutter ( 1626): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:551:7)
E/flutter ( 1626): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18)
E/flutter ( 1626): &lt;asynchronous suspension&gt;
E/flutter ( 1626): #2      launch (package:url_launcher/url_launcher.dart:66:19)
E/flutter ( 1626): #3      _ReadingViewState.build.&lt;anonymous closure&gt; (package:cat_dog/modules/dashboard/components/ReadingView.dart:57:23)
E/flutter ( 1626): &lt;asynchronous suspension&gt;
E/flutter ( 1626): #4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
E/flutter ( 1626): #5      _InkResponseState.build.&lt;anonymous closure&gt; (package:flutter/src/material/ink_well.dart:562:30)
E/flutter ( 1626): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter ( 1626): #7      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
E/flutter ( 1626): #8      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
E/flutter ( 1626): #9      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter ( 1626): #10     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter ( 1626): #11     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter ( 1626): #12     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19)
E/flutter ( 1626): #13     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
E/flutter ( 1626): #14     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
E/flutter ( 1626): #15     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 1626): #16     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
E/flutter ( 1626): #17     _invoke1 (dart:ui/hooks.dart:168:13)
E/flutter ( 1626): #18     _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)"><pre class="notranslate"><code class="notranslate">E/MethodChannel#plugins.flutter.io/url_launcher( 1626): Failed to handle method call
E/MethodChannel#plugins.flutter.io/url_launcher( 1626): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.app.ContextImpl.startActivity(ContextImpl.java:672)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.app.ContextImpl.startActivity(ContextImpl.java:659)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at io.flutter.plugins.urllauncher.UrlLauncherPlugin.onMethodCall(UrlLauncherPlugin.java:61)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.os.MessageQueue.next(MessageQueue.java:323)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.os.Looper.loop(Looper.java:135)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at android.app.ActivityThread.main(ActivityThread.java:5417)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/MethodChannel#plugins.flutter.io/url_launcher( 1626):         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/flutter ( 1626): [ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter ( 1626): PlatformException(error, Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?, null)
E/flutter ( 1626): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:551:7)
E/flutter ( 1626): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:292:18)
E/flutter ( 1626): &lt;asynchronous suspension&gt;
E/flutter ( 1626): #2      launch (package:url_launcher/url_launcher.dart:66:19)
E/flutter ( 1626): #3      _ReadingViewState.build.&lt;anonymous closure&gt; (package:cat_dog/modules/dashboard/components/ReadingView.dart:57:23)
E/flutter ( 1626): &lt;asynchronous suspension&gt;
E/flutter ( 1626): #4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
E/flutter ( 1626): #5      _InkResponseState.build.&lt;anonymous closure&gt; (package:flutter/src/material/ink_well.dart:562:30)
E/flutter ( 1626): #6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter ( 1626): #7      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
E/flutter ( 1626): #8      TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
E/flutter ( 1626): #9      PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter ( 1626): #10     PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter ( 1626): #11     PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter ( 1626): #12     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19)
E/flutter ( 1626): #13     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
E/flutter ( 1626): #14     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
E/flutter ( 1626): #15     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 1626): #16     _WidgetsFlutterBinding&amp;BindingBase&amp;GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
E/flutter ( 1626): #17     _invoke1 (dart:ui/hooks.dart:168:13)
E/flutter ( 1626): #18     _dispatchPointerDataPacket (dart:ui/hooks.dart:122:5)
</code></pre></div>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Analyzing cat_dog...
No issues found! (ran in 16.7s)"><pre class="notranslate"><code class="notranslate">Analyzing cat_dog...
No issues found! (ran in 16.7s)
</code></pre></div>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.5 17F77, locale en-VN)
    • Flutter version 1.0.0 at /Users/mac-lt108/Documents/flutter
    • Framework revision 5391447fae (12 days ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/mac-lt108/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/mac-lt108/Library/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_152-release-915-b08)
    • All Android licenses accepted.

[!] iOS toolchain - develop for iOS devices (Xcode 9.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.3, Build version 9E145
    ✗ Verify that all connected devices have been paired with this computer in Xcode.
      If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
      To update with Brew, run:
        brew update
        brew uninstall --ignore-dependencies libimobiledevice
        brew uninstall --ignore-dependencies usbmuxd
        brew install --HEAD usbmuxd
        brew unlink usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    • ios-deploy 2.0.0
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.0)
    • 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_152-release-915-b08)

[✓] Connected device (2 available)
    • Google Nexus 5X, 6 0 0, API 23, 1080x1920 • 192.168.56.102:5555                      • android-x86 • Android 6.0 (API 23)
    • IBL020                                    • 4afcab750f170bacf52696158e2fbc69295b79b9 • ios         • iOS 11.2.1

! Doctor found issues in 1 category."><pre class="notranslate"><code class="notranslate">[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.5 17F77, locale en-VN)
    • Flutter version 1.0.0 at /Users/mac-lt108/Documents/flutter
    • Framework revision 5391447fae (12 days ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/mac-lt108/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/mac-lt108/Library/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_152-release-915-b08)
    • All Android licenses accepted.

[!] iOS toolchain - develop for iOS devices (Xcode 9.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.3, Build version 9E145
    ✗ Verify that all connected devices have been paired with this computer in Xcode.
      If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.
      To update with Brew, run:
        brew update
        brew uninstall --ignore-dependencies libimobiledevice
        brew uninstall --ignore-dependencies usbmuxd
        brew install --HEAD usbmuxd
        brew unlink usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    • ios-deploy 2.0.0
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.0)
    • 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_152-release-915-b08)

[✓] Connected device (2 available)
    • Google Nexus 5X, 6 0 0, API 23, 1080x1920 • 192.168.56.102:5555                      • android-x86 • Android 6.0 (API 23)
    • IBL020                                    • 4afcab750f170bacf52696158e2fbc69295b79b9 • ios         • iOS 11.2.1

! Doctor found issues in 1 category.
</code></pre></div>