Flutter:从Activity上下文外部调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志

时间:2018-11-27 10:21:43

标签: dart flutter

我正在尝试

launch("tel://21213123123")

但是,我遇到了以下错误!

PlatformException (PlatformException(error, Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?, null))

在此文件中

message_codecs.dart

这是我的错误日志

E/MethodChannel#plugins.flutter.io/url_launcher(26131): Failed to handle method call
E/MethodChannel#plugins.flutter.io/url_launcher(26131): 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(26131):     at android.app.ContextImpl.startActivity(ContextImpl.java:672)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at android.app.ContextImpl.startActivity(ContextImpl.java:659)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at io.flutter.plugins.urllauncher.UrlLauncherPlugin.onMethodCall(UrlLauncherPlugin.java:61)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at android.os.MessageQueue.next(MessageQueue.java:323)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at android.os.Looper.loop(Looper.java:135)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at android.app.ActivityThread.main(ActivityThread.java:5468)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
E/MethodChannel#plugins.flutter.io/url_launcher(26131):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:671)

1 个答案:

答案 0 :(得分:5)

新版本的urlLauncher 4.0.2插件也遇到了相同的问题

我降级到3.0.3,并且一切正常,因此存储库中可能存在错误。

pubspec.yaml

<ul>
    <li *ngFor="let list of List1">{{list.name}}        
        <ul *ngIf="list.name === 'C'">
            <li *ngFor="let list_2 of List2" >{{ list_2.name }}
            </li>
        </ul>
    </li>
</ul>

示例代码(摘自git repo,但对我而言适用于3.0.3)

https://github.com/flutter/plugins/tree/master/packages/url_launcher

 url_launcher: 3.0.3

有关该插件的所有可用版本,请参见此处。 https://pub.dartlang.org/packages/url_launcher#-changelog-tab-

相关问题