有没有办法在android中实现OpenUrl功能(如iOS OpenUrl)?
例如,
如果用户从网页(在浏览器中)重定向到“myapp://main
”,
android 将启动我的应用程序。
最佳答案
答案只是将其添加到您要启动的 Activity 中的 list 中:
<activity
android:name="com.dimrix.something.BootActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="SomeScheme" />
<data android:scheme="otherScheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
并且比在浏览器内编写
一些方案://
或
其他方案://
它将开始 Activity ......
如果您想通过获取 Activity 中的 Intent 数据来根据 url 执行操作,您甚至可以在方案之后发送信息
Uri data = getIntent().getData();
这样你就可以写
SomeScheme://水
并用 Uri 数据响应“水”。
关于android - Android 中的 iOS OpenUrl 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23763781/