我有一个自定义链接:callnumber://12345
我想通过以下方式捕获此链接的点击事件:
<activity android:name=".Test"
android:label="@string/app_name">
<intent-filter>
<data android:scheme="callnumber"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
我已经在许多设备上进行了测试,例如:Samsung galaxy S2、Samsung Galaxy 2、Motorola XT720 , 它运行完美,但在 HTC Sensation Z710e 上,它没有工作。
我发现在 HTC Sensation Z710e 上,该链接变成 http://www.callnumber.com// 并用浏览器打开。
我像这样转动我的 intent-filter,它起作用了:
<intent-filter>
<data android:scheme="http" android:host="www.callnumber.com"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
但是我不想抓取http scheme,因为从custom改成http scheme很容易丢数据。
示例:如果我的链接是 callnumber://12345# ,它将变成 http://www.callnumber.com//12345 ,它丢失了我的字符 '#'
或者如果我的链接是 callnumber://12345#34567 ,它将变成 http://www.callnumber.com//12345 ,它丢失了我的 '#34567'
使用上面的 android 设备列表(HTC Sensation Z710e 除外),它返回我想要的数据。
那么如何为所有 Android 设备或至少为 HTC Sensation Z710e 捕获自定义方案?
非常感谢,
最佳答案
添加数据线如下:
<data android:host="*" android:scheme="callnumber" />
关于android:scheme 在我的设备上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10246763/