简体   繁体   English

我将如何在我的 android 应用程序中打开我的网站

[英]How will I open my website inside my android app

Hello I have a webview android app.您好,我有一个 webview android 应用程序。 When someone open my app.当有人打开我的应用程序时。 my website opens inside app as webview application.我的网站在应用程序内作为 webview 应用程序打开。 But I want to open url inside app when someone call my website url in own browser.但是当有人在自己的浏览器中调用我的网站 url 时,我想在应用程序内打开 url。

Eg when i call www.fb.com/somepage , facebook opens directly own application inside my phone.例如,当我拨打 www.fb.com/somepage 时,facebook 会直接在我的手机中打开自己的应用程序。 I dont visit page over browser I try to do like this.我不通过浏览器访问页面我尝试这样做。 How will I do ?我会怎么做?

I searched everyrhing i imagine, i could not find helpful articles about it.我搜索了我想象的所有内容,但找不到关于它的有用文章。 I searched supported urls or supported webpages for android.我搜索了 android 支持的 url 或支持的网页。 I found a lot of things.我发现了很多东西。 They wrote a lot of codes.他们写了很多代码。 i dont think i need a lot of codes for catch my website urls.我不认为我需要很多代码来捕捉我的网站网址。 am not i right ?我不对吗?

I have already webview application.我已经有了 webview 应用程序。 if i will do easy way like something change in manifest or my mainactivity file.如果我会做一些简单的方法,比如清单或我的主要活动文件中的某些更改。 I want to do like this way.我想这样做。

Thank you for help谢谢你的帮助

What is needed is an intent-filter for your View action that you'd link to a url scheme .需要的是您要链接到url scheme 的View操作的intent-filter

In your Manifest XML file... The View intent represents the action while the BROWSABLE category responds to web URIs.在您的清单 XML 文件中... View 意图表示操作,而 BROWSABLE 类别响应 Web URI。

Defining the scheme定义方案

<activity android:name=".MainActivity>
    <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="http" 
         android:host="your-website.com" 
         android:path="/somepage/" />
    </intent-filter>
</activity> 

However, the user must have your app already installed or else s/he will get an error message in the browser.但是,用户必须已经安装了您的应用程序,否则他/她将在浏览器中收到错误消息。 You would abslutely need a fallback.你绝对需要一个后备。 One way to deal with the error problem is to use some Javascript check to verify if user has the app installed (if you are using a Javascript like AngularJS you can bind it to an onclick. If not you can use a redirect of some kind with Javascript or without).处理错误问题的一种方法是使用一些 Javascript 检查来验证用户是否安装了应用程序(如果您使用的是 AngularJS 之类的 Javascript,您可以将其绑定到 onclick。如果没有,您可以使用某种重定向Javascript 或没有)。 If the app is not installed, the user goes to the regular website url.如果未安装该应用程序,用户将转到常规网站 url。 Else, s/he jumps to app.否则,他/她会跳转到应用程序。

Handling redirections for users who do not have the app installed为未安装应用程序的用户处理重定向

In your website file or in your template file, use Javascript在您的网站文件或模板文件中,使用 Javascript

<script>
  //any conditional logic 
  if( navigator.userAgent.match(/android/i) ) {
  // redirect to App
  } else {
  // stay/redirect to website or something like getting them to install the app  
  }
</script>

Now when the user clicks on <a href="http://yourweb.com/somepage/">Your Text </a> , s/he gets to the app but if the app is not installed s/he gets to the page on the browser or the Play Store (see notes below).现在,当用户点击<a href="http://yourweb.com/somepage/">Your Text </a> ,他/她会进入该应用程序,但如果该应用程序未安装,他/他/她将进入浏览器或 Play 商店中的页面(请参阅下面的注释)。

Other options其他选项

There is another way of doing all of the above .还有另一种方法可以完成上述所有操作 Instead of defing an http scheme, you could have your own custom URI.您可以拥有自己的自定义 URI,而不是定义 http 方案。

<intent-filter>
  <data android:scheme="your-custom-URI" />

</intent-filter>

and in your web template file within some sort of conditionals for the redirection fallback...并在您的 Web 模板文件中为重定向回退提供某种条件......

<a href="your-custom-URI://somepage">Your Text</a>

Extra Notes额外说明

  • Something that would need your attention concerns some browser specifics.需要您注意的事情涉及某些浏览器的细节。 Here is how Google Chrome treats the subject .以下是 Google Chrome处理该主题的方式

  • If have your app on the Play Store you can refer the user to market://details?id=com.your.app.package to download it.如果您的应用在 Play 商店中,您可以推荐用户到market://details?id=com.your.app.package下载它。

  • You can achieve more than that with some Javascript library such as AngularJS, Vue, etc in your website.您可以在您的网站中使用一些 Javascript 库(例如 AngularJS、Vue 等)实现更多功能。

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

相关问题 如何通过对话框从我的网站打开 android 应用程序? - How to open an android app from my website with a dialog box? 如何通过共享屏幕打开我的 Android 应用程序? - How can I open my Android app through share screen? 在android中共享图像时如何防止其他应用程序在他们的应用程序中打开我的应用程序? - How to prevent other app open my app inside their app when sharing image in android? Android:如何自动打开我的应用程序? - Android: how to have my app open automatically? ANDROID:Facebook和浏览器在我的应用程序内打开,而不是在自己的应用程序中 - ANDROID: Facebook and Browser Open inside my app, not in their own 如何从 firebase 存储链接在我的应用程序(android studio,JAVA)中打开 pdf 文件 - How to open pdf file inside my app (android studio, JAVA) from firebase storage link 如何在我的Android应用程序中截取屏幕截图 - How to take a screenshot inside my android app 如何检测用户何时单击了我的应用程序的 webview 中加载的网站的特定按钮? - How can I detect when a user clicked a particular button of a website loaded inside the webview of my app? android无法打开我的应用 - android cannot open my app 我如何从Android中自己的应用程序打开Splashtop应用程序 - How i can open a splashtop app from my own app in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM