任何人都可以指导我如何从Android浏览器启动我的Android应用程序?
是否可以建立如下链接:
<a href="anton://useful_info_for_anton_app">click me!</a>
Run Code Online (Sandbox Code Playgroud)
导致我的Anton应用程序启动?
我知道这适用于具有市场协议的Android Market应用程序,但是可以与其他应用程序类似吗?
以下是启动Android电子市场的链接示例:
<a href="market://search?q=pname:com.nytimes.android">click me!</a>
Run Code Online (Sandbox Code Playgroud)
更新:
我接受eldarerat提供的答案很有用,但我只想提一下,我对<intent-filter>标签的子元素的顺序有些麻烦.我建议您只<intent-filter>使用该标签中的新子元素制作另一个,以避免我遇到的问题.例如我AndroidManifest.xml看起来像这样:
<activity android:name=".AntonWorld"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="anton" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud) 我尝试使用自己的方案从浏览器启动我的应用程序时遇到问题.
代码如下:
清单文件:
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:exported="false">
<intent-filter>
<data android:scheme="allplayer" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
Html文件:
<html>
<head>
</head>
<body>
<a href="allplayer://site.com">Test link</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果我点击链接,我的应用程序将无法启动.我做了很多研究,但找不到答案.
如果我用http更改allplayer一切正常.
通过此链接,我了解到不建议您使用自己的方案.这是否意味着你自己的计划不起作用?这里
的人正在使用自己的方案,从他的反馈来看,它似乎正在发挥作用.
我错过了什么吗?
我正在为我的研究开发一个Android应用程序,我正在使用OAuth(路标库)来访问来自Web服务的用户数据,这也是开发过程的一部分.我能够完成OAuth的常用步骤,并使用Uri(用于回调应用程序),并且可以进入我调用设备浏览器的步骤,选择验证我的应用程序,下一步是支持将浏览器重定向到应用程序....
相反,我得到一个错误,上面写着"你没有权限打开:
appSchema:// appName?authorizationSensitiveInfo ..."'后面的附件?' 是来自服务的oauth_token和oauth_verifier(我们可以假设所有步骤直到重定向"正确").
可能存在的问题在于该appSchema://appName部分.根据我的理解,这是重定向URL,告诉Uri使用手机的浏览器来定位我的应用程序并调用onResume()方法.来自哪里的值appSchema://appName(在清单中定义?如果是这样的话?).
为什么问题有权限?我必须为我的Uri设置权限才能访问我的应用吗?我迷路了...如果你需要代码片段来帮助我请回复,我没有包含任何代码,因为这更像是我错过的一个概念......我现在不在我的机器上但是我可以提供代码,如果这将使事情更容易理解.真的在这里打我的脑袋......
响应一个伟大的答案在这里我如何处理我的恢复
protected void onResume() {
super.onResume();
Uri uri = this.getIntent().getData();
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
Log.d("StepGreenM", uri.toString());
String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
Log.d("StepGreenM", verifier);
try {
provider.retrieveAccessToken(consumer, verifier);
TOKEN = consumer.getToken();
REQUEST_SECRET = consumer.getTokenSecret();
Log.d("StepGreenM", TOKEN);
Log.d("StepGreenM", REQUEST_SECRET);
} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
}
}
uri = getIntent().getData(); …Run Code Online (Sandbox Code Playgroud) 我有一个HTML文件,如果我在Android原生浏览器中打开它,它会启动一个应用程序,但当我尝试在WebView中打开它时,它无法启动该应用程序,并显示"网页不可用".我认为我的WebView无法处理为应用程序定义的方案"my.special.scheme://".
我从浏览器中读取了启动Android应用程序,但它没有涵盖有关从WebView启动应用程序的信息.