我使用 Intent 从网站向 Progressive Web App 发送消息。只是为了在本机代码中显示 admob 广告。我发现的最佳解决方案是将代码添加到
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
showInterstatial();
简单而有效,但只有一次。据我了解,当我使用 onNewIntent 时,它是替换 onCreate 而不是在哪里注册活动android:launchMode="singleInstance"
和
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="octoads"/>
</intent-filter>
当我多次使用这个意图时,我得到了这个错误:
Process: online.octonauts.creaturer, PID: 709
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=octoads://octon.online?m=inter pkg=com.android.chrome (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2100)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1747)
at android.app.Activity.startActivityForResult(Activity.java:5465)
at android.app.Activity.startActivityForResult(Activity.java:5423)
at android.app.Activity.startActivity(Activity.java:5809)
at androidx.core.content.ContextCompat$Api16Impl.startActivity(ContextCompat.java:830)
at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:279)
at androidx.browser.trusted.TrustedWebActivityIntent.launchTrustedWebActivity(TrustedWebActivityIntent.java:48)
at com.google.androidbrowserhelper.trusted.TwaLauncher.launchWhenSplashScreenReady(TwaLauncher.java:273)
at com.google.androidbrowserhelper.trusted.TwaLauncher.lambda$launchWhenSessionEstablished$4$com-google-androidbrowserhelper-trusted-TwaLauncher(TwaLauncher.java:257)
at com.google.androidbrowserhelper.trusted.TwaLauncher$$ExternalSyntheticLambda3.run(Unknown Source:6)
at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.lambda$onSplashImageTransferred$1$com-google-androidbrowserhelper-trusted-splashscreens-PwaWrapperSplashScreenStrategy(PwaWrapperSplashScreenStrategy.java:208)
at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy$$ExternalSyntheticLambda1.run(Unknown Source:4)
at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.runWhenEnterAnimationComplete(PwaWrapperSplashScreenStrategy.java:215)
at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.onSplashImageTransferred(PwaWrapperSplashScreenStrategy.java:207)
at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy.lambda$configureTwaBuilder$0$com-google-androidbrowserhelper-trusted-splashscreens-PwaWrapperSplashScreenStrategy(PwaWrapperSplashScreenStrategy.java:195)
at com.google.androidbrowserhelper.trusted.splashscreens.PwaWrapperSplashScreenStrategy$$ExternalSyntheticLambda0.onFinished(Unknown Source:6)
at com.google.androidbrowserhelper.trusted.splashscreens.SplashImageTransferTask$1.onPostExecute(SplashImageTransferTask.java:144)
at com.google.androidbrowserhelper.trusted.splashscreens.SplashImageTransferTask$1.onPostExecute(SplashImageTransferTask.java:91)
at android.os.AsyncTask.finish(AsyncTask.java:771)
at android.os.AsyncTask.access$900(AsyncTask.java:199)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8582)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:563)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1133)
```