简体   繁体   English

android自定义方案和chrome intent

[英]android custom scheme and chrome intent

I have a cross platform app developed in Xamarin. 我有一个用Xamarin开发的跨平台应用程序。 In the iOS version I use a custom url scheme to load a specific web page in a web view, such as 在iOS版本中,我使用自定义网址方案在网络视图中加载特定网页,例如

myapp://?returnUrl=http:/google.com.au myapp://?returnUrl = http:/google.com.au

As a customer has few other applications from us, he wants to keep the custom scheme in the same format. 由于客户从我们这里收到的其他应用程序很少,因此他希望将自定义方案保持相同的格式。 In the android I found that such intent can be opened from Firefox, but not form email or Chrome. 在android系统中,我发现可以从Firefox打开这种意图,但不能通过电子邮件或Chrome打开。 I found that Chrome needs a custom intent to make it work . 我发现Chrome需要自定义意图才能使其正常运行 I tried to implement that but couldn't make it work. 我尝试实现该功能,但无法使其正常工作。

Here is my manifest implementation: 这是我的清单实现:

[Activity(Label = "MyApp",
    MainLauncher = true,
    LaunchMode = LaunchMode.SingleTask,
    ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize)]
[IntentFilter(new[] { Intent.ActionView },
    Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
    DataScheme = "myapp")]

wich will create a following manifest file: wich将创建以下清单文件:

<activity android:configChanges="orientation|screenSize" android:label="MyApp" android:launchMode="singleTask" android:name="myapp.auth.droid.MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <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="myapp" />
  </intent-filter>
</activity>

I tried to capture an intent from Firefox and convert it to URI in the application, but following intent is not working from Chrome (it works from Firefox BTW): 我试图从Firefox中捕获一个意图并将其转换为应用程序中的URI,但是以下意图在Chrome中不起作用(它在Firefox BTW中有效):

myapp://?returnUrl=http:/google.com.au#Intent;action=android.intent.action.VIEW;launchFlags=0x4400000;component=MyApp.MyApp/myapp.auth.droid.MainActivity;end myapp://?returnUrl = http:/google.com.au#Intent; action = android.intent.action.VIEW; launchFlags = 0x4400000; component = MyApp.MyApp / myapp.auth.droid.MainActivity; end

Am I missing something? 我想念什么吗?

NOTE . 注意 http:// scheme can be used but it is not a preferred option. 可以使用http://方案,但不是首选方案。

NOTE 2 . 注2 I use Nexus 5, Android 4.4.4 我使用的是Nexus 5,Android 4.4.4

for chrome, you need to use the chrome intent, the old way is no longer supported in the after version 18 对于chrome,您需要使用chrome intent,在18版之后的版本中不再支持旧方法

The intent should look like something in this format 目的看起来应该像这种格式

intent://some_optional_data#Intent;scheme=app_scheme;package=package_name;end

check out this site for more detail information: Android Intents with Chrome 请访问此网站以获取更多详细信息: 带有Chrome的Android Intent

This method would also fall back to google play as well 这种方法也将回到Google Play上

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

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