简体   繁体   English

从 TWA 切换到其他活动

[英]Switch to a different activity from TWA

I've put together a PWA and wanted to convert it into an Android App.我已经组装了一个 PWA 并想将它转换成一个 Android 应用程序。 I've done so and my Android app consists of Main Activity and TWA that I start from the Main Activity.我已经这样做了,我的 Android 应用程序由主活动和从主活动开始的 TWA 组成。

Is there a way to switch from inside the TWA to some other activity on some event in the PWA running in this TWA?有没有办法从 TWA 内部切换到此 TWA 中运行的 PWA 中某个事件的其他活动? Like button click.喜欢按钮点击。 Preferably from the HTML/Javascript of the PWA itself.最好来自 PWA 本身的 HTML/Javascript。

The end goal is to ad ads to the app (I'm using some paid APIs in the PWA so I need to at least break even and cannot monetize it on the web development side since Google AdSense and likes need context rich web-apps like blogs) and I've figured out that Google AdMob don't show up in TWA, they require a native Android Activity.最终目标是向应用程序投放广告(我在 PWA 中使用了一些付费 API,因此我至少需要实现收支平衡,并且无法在 Web 开发方面通过它获利,因为 Google AdSense 和喜欢需要上下文丰富的 Web 应用程序,例如博客)并且我发现 Google AdMob 不会出现在 TWA 中,它们需要原生的 Android Activity。

This question is closely related but I don't know where to put this URI: Launching another activity from a Trusted Web Activity (TWA)这个问题密切相关,但我不知道把这个 URI 放在哪里: 从可信 Web 活动 (TWA) 启动另一个活动

Thank you!谢谢!

Yes, it is possible to start a different Activity.是的,可以启动不同的活动。 You will need to define a custom schema and link to that schema from the PWA:您需要定义一个自定义架构并从 PWA 链接到该架构:

This is defined inside AndroidManifest.xml , where the Activity you want to open from the PWA is specified.这是在AndroidManifest.xml中定义的,其中指定了要从 PWA 打开的 Activity。 In the example below, we want to open ReviewActivity from the PWA, so we define:在下面的示例中,我们希望从 PWA 打开ReviewActivity ,因此我们定义:

  <activity android:name=".ReviewActivity"
      android:theme="@android:style/Theme.Translucent.NoTitleBar">
      <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="doom-fire" android:host="review" />
      </intent-filter>
  </activity>

Then, in the web application, whenever you link to doom-fire://review , ReviewActivity will be opened:然后,在 Web 应用程序中,每当您链接到doom-fire://review ,都会打开ReviewActivity

<a href="doom-fire://review">Rate app now!</a>

I wrote a complete blogpost for the in-app review use-case that you may want to check out.我为您可能想要查看的应用内评论用例写了一篇完整的博客文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM