从浏览器中打开Intent网址

时间:2019-11-04 12:56:20

标签: android android-intent

我有一个移动设备({ "type": "record", "namespace": "com.lm.gde.eventing.avro", "name": "EnrichedPolicyEventAvro", "version": "1", "fields": [{ "name": "eventType", "type": "string" }, { "name": "correlationId", "type": "string" }, { "name": "timestamp", "type": "long" }, { "name": "policy", "type": { "type": "record", "name": "PolicyAvro", "fields": [{ "name": "policyNumber", "type": "string" }, { "name": "policyId", "type": "string" }, { "name": "customerNumber", "type": "string" }, { "name": "effectiveDate", "type": "string" }, { "name": "expirationDate", "type": "string" }, { "name": "transactionEffectiveDate", "type": "string" }, { "name": "revisionNumber", "type": "string" }, { "name": "policyStatusCd", "type": "string" }, { "name": "previousPolicyVersionId", "type": "string" }, { "name": "transactionTypeCd", "type": "string" }, { "name": "vehicles", "type": { "type": "array", "items": { "name": "vehicles", "type": "record", "fields":[ { "name": "registrationNo", "type": "string" }, { "name": "make", "type": "string" }, { "name": "model", "type": "string" }, { "name": "coverages", "type": { "type": "record", "name": "coverages", "fields": [{ "name": "roadAssistanceCoverLevelCd", "type": "string" }] } } ] } } }, { "name": "customer", "type": { "type": "record", "name": "customer", "fields": [{ "name": "extensionFields", "type": { "type": "record", "name": "extensionFields", "fields": [{ "name": "nif", "type": "string" }] } }, { "name": "individualDetails", "type": { "type": "record", "name": "individualDetails", "fields": [{ "name": "firstName", "type": "string" }, { "name": "lastName", "type": "string" } ] } }, { "name": "phones", "type": { "type": "array", "items": { "name": "phoneNumber", "type": "record", "fields":[ { "name": "phoneNumber", "type": "string" } ] } } }, { "name": "addresses", "type": { "type": "array", "items": { "name": "address", "type": "record", "fields":[ { "name": "addressLine1", "type": "string" }, { "name": "addressLine2", "type": "string" }, { "name": "addressLine3", "type": "string" }, { "name": "city", "type": "string" }, { "name": "postalCode", "type": "string" } ] } } } ] } }, { "name": "previous_policy", "type": { "type": "record", "name": "previous_policy", "fields": [{ "name": "vehicles", "type": { "type": "array", "items": { "name": "VehiclesPreviousPolicy", "type": "record", "fields": [{ "name": "registrationNo", "type": "string" }, { "name": "coverages", "type": { "type": "record", "name": "CoveragesPreviousPolicy", "fields": [{ "name": "roadAssistanceCoverLevelCd", "type": "string" }] } } ] } } }, { "name": "policyNumber", "type": "string" }, { "name": "policyId", "type": "string" }, { "name": "customerNumber", "type": "string" }, { "name": "effectiveDate", "type": "string" }, { "name": "expirationDate", "type": "string" }, { "name": "transactionEffectiveDate", "type": "string" }, { "name": "policyStatusCd", "type": "string" }, { "name": "transactionTypeCd", "type": "string" }, { "name": "revisionNumber", "type": "string" }, { "name": "previousPolicyVersionId", "type": "string" } ] } } ] } } ] } Android)使用的asp经典站点,该站点使用Intent通过javascript调用了本机应用程序。有时它可以工作,而其他时候却无法打开应用程序。在iOS中,它始终有效。通话就像

iOS

Android可以控制或验证意图URL吗?

3 个答案:

答案 0 :(得分:0)

在AndroidManufest.xml中设置了要从浏览器的意图过滤器中打开的活动:

   <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="yourscheme"/>
    </intent-filter>

然后在Activity的onCreate()方法中捕获该意图并执行您想做的任何事情:

val intent = intent
    if (Intent.ACTION_VIEW == intent.action) {
        val uri = intent.data
        if (uri?.host?.matches("something_you_need") == true) {
            doSomething(token)
        } else {
            doSomethingElse()
        }
    }

然后,您可以在网络上调用类似yourscheme://something_you_need

答案 1 :(得分:0)

An intent URI has the following layout (all optional - heh!)

intent:
   HOST/URI-path // Optional host 
   #Intent; 
      package=[string]; 
      action=[string]; 
      category=[string]; 
      component=[string]; 
      scheme=[string]; 
      type=[string]
      S.*=[string];
   end; 

Link : https://paul.kinlan.me/every-browser-should-support-intent-urls/

使用此链接。

答案 2 :(得分:0)

嗯,问题不是我所说的意图的方式,问题是浏览器。它与所有旧版浏览器(除了旧的mozilla版本)在桌面版本下均可完美搭配。 通过移动设备进行访问时,如上所述,问题仅发生在android设备上,该解决方案一直使用“ Opera”浏览器,因为它对发送数据没有限制。我的应用程序发送Base64数据,因此当发送超过3 Mb的aprox时,Chrome和Samsung浏览器给我错误。我也尝试将mozilla用于android,但是它有一个很大的问题,那就是不能安装用户证书(真可惜!),所以最终在Opera中,所有过程都可以正常进行:)

希望这会帮助其他人像我一样在其中战斗;)