谁能指导我如何从android浏览器启动我的android应用程序?
当前回答
Xamarin port对菲利克斯的回答
在MainActivity中添加这个(docs: Android.App.IntentFilterAttribute Class):
....
[IntentFilter(new[] {
Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "my.special.scheme")
]
public class MainActivity : Activity
{
....
Xamarin将为你在AndroidManifest.xml中添加以下内容:
<activity
android:label="Something"
android:screenOrientation="portrait"
android:theme="@style/MyTheme"
android:name="blah.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="my.special.scheme" />
</intent-filter>
</activity>
为了获得参数(我在MainActivity的OnCreate中测试):
var data = Intent.Data;
if (data != null)
{
var scheme = data.Scheme;
var host = data.Host;
var args = data.PathSegments;
if (args.Count > 0)
{
var first = args[0];
var second = args[1];
...
}
}
据我所知,以上内容可以添加到任何活动中,不仅仅是MainActivity
注:
当用户点击链接,Android操作系统重新启动你的应用程序(杀死前实例,如果有,并运行新的一个),意味着应用程序的MainLauncher活动的OnCreate事件将再次被触发。 这个链接:<a href="my.special. "方案://host/arg1/arg2">,在上面最后的代码段的值将是:
scheme: my.special.scheme
host: host
args: ["arg1", "arg2"]
first: arg1
second: arg2
更新:如果android创建你的应用程序的新实例,你应该添加android:launchMode="singleTask"太。
其他回答
example.php:
<?php
if(!isset($_GET['app_link'])){ ?>
<iframe src="example.php?app_link=YourApp://blabla" style="display:none;" scrolling="no" frameborder="0"></iframe>
<iframe src="example.php?full_link=http://play.google.com/xyz" style="display:none;" scrolling="no" frameborder="0"></iframe>
<?php
}
else { ?>
<script type="text/javascript">
self.window.location = '<?php echo $_GET['app_link'];?>';
window.parent.location.href = '<?php echo $_GET['full_link'];?>';
</script>
<?php
}
你需要添加一个伪主机名到CALLBACK_URL 'app://'作为URL没有意义,不能被解析。
Felix处理深度链接的方法是处理深度链接的典型方法。我还建议您查看这个库来处理深层链接的路由和解析:
https://github.com/airbnb/DeepLinkDispatch
您可以使用注释为特定的深链接URI注册Activity,它将为您提取参数,而不必执行获取路径段、匹配它等通常的繁琐操作。你可以像这样简单地注释和活动:
@DeepLink("somePath/{someParameter1}/{someParameter2}")
public class MainActivity extends Activity {
...
}
Xamarin port对菲利克斯的回答
在MainActivity中添加这个(docs: Android.App.IntentFilterAttribute Class):
....
[IntentFilter(new[] {
Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "my.special.scheme")
]
public class MainActivity : Activity
{
....
Xamarin将为你在AndroidManifest.xml中添加以下内容:
<activity
android:label="Something"
android:screenOrientation="portrait"
android:theme="@style/MyTheme"
android:name="blah.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="my.special.scheme" />
</intent-filter>
</activity>
为了获得参数(我在MainActivity的OnCreate中测试):
var data = Intent.Data;
if (data != null)
{
var scheme = data.Scheme;
var host = data.Host;
var args = data.PathSegments;
if (args.Count > 0)
{
var first = args[0];
var second = args[1];
...
}
}
据我所知,以上内容可以添加到任何活动中,不仅仅是MainActivity
注:
当用户点击链接,Android操作系统重新启动你的应用程序(杀死前实例,如果有,并运行新的一个),意味着应用程序的MainLauncher活动的OnCreate事件将再次被触发。 这个链接:<a href="my.special. "方案://host/arg1/arg2">,在上面最后的代码段的值将是:
scheme: my.special.scheme
host: host
args: ["arg1", "arg2"]
first: arg1
second: arg2
更新:如果android创建你的应用程序的新实例,你应该添加android:launchMode="singleTask"太。
嘿,我有办法了。我没有将类别设置为“默认”。此外,我使用的主要活动的意图数据。现在我正在使用一个不同的活动的意图数据。谢谢你的帮助。:)
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。