ear*_*ing 5 android android-intent
我试图使用意图锚描述启动我的应用程序在这里.我能够使用这种语法启动我的应用程序,
<a href="intent://#Intent;scheme=http;package=com.example.myapp;end">Launch my app</a>
Run Code Online (Sandbox Code Playgroud)
但我不知道许多不同的元素是什么意思.
基于intent的URI的基本语法如下:
意图:
Run Code Online (Sandbox Code Playgroud)HOST/URI-path // Optional host #Intent; package=[string]; action=[string]; category=[string]; component=[string]; scheme=[string]; end;
Dav*_*ser 10
这是toUri()来自Intent班级的方法:
public String toUri(int flags) {
StringBuilder uri = new StringBuilder(128);
String scheme = null;
if (mData != null) {
String data = mData.toString();
if ((flags&URI_INTENT_SCHEME) != 0) {
final int N = data.length();
for (int i=0; i<N; i++) {
char c = data.charAt(i);
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|| c == '.' || c == '-') {
continue;
}
if (c == ':' && i > 0) {
// Valid scheme.
scheme = data.substring(0, i);
uri.append("intent:");
data = data.substring(i+1);
break;
}
// No scheme.
break;
}
}
uri.append(data);
} else if ((flags&URI_INTENT_SCHEME) != 0) {
uri.append("intent:");
}
uri.append("#Intent;");
if (scheme != null) {
uri.append("scheme=").append(scheme).append(';');
}
if (mAction != null) {
uri.append("action=").append(Uri.encode(mAction)).append(';');
}
if (mCategories != null) {
for (String category : mCategories) {
uri.append("category=").append(Uri.encode(category)).append(';');
}
}
if (mType != null) {
uri.append("type=").append(Uri.encode(mType, "/")).append(';');
}
if (mFlags != 0) {
uri.append("launchFlags=0x").append(Integer.toHexString(mFlags)).append(';');
}
if (mPackage != null) {
uri.append("package=").append(Uri.encode(mPackage)).append(';');
}
if (mComponent != null) {
uri.append("component=").append(Uri.encode(
mComponent.flattenToShortString(), "/")).append(';');
}
if (mSourceBounds != null) {
uri.append("sourceBounds=")
.append(Uri.encode(mSourceBounds.flattenToString()))
.append(';');
}
if (mExtras != null) {
for (String key : mExtras.keySet()) {
final Object value = mExtras.get(key);
char entryType =
value instanceof String ? 'S' :
value instanceof Boolean ? 'B' :
value instanceof Byte ? 'b' :
value instanceof Character ? 'c' :
value instanceof Double ? 'd' :
value instanceof Float ? 'f' :
value instanceof Integer ? 'i' :
value instanceof Long ? 'l' :
value instanceof Short ? 's' :
'\0';
if (entryType != '\0') {
uri.append(entryType);
uri.append('.');
uri.append(Uri.encode(key));
uri.append('=');
uri.append(Uri.encode(value.toString()));
uri.append(';');
}
}
}
uri.append("end");
return uri.toString();
}
Run Code Online (Sandbox Code Playgroud)
如果您可以阅读Java代码,那么应该非常清楚这里发生了什么.在任何情况下,额外的东西都可以放在URL中,它们看起来像这样:
<type>.<key>=<value>;
Run Code Online (Sandbox Code Playgroud)
其中<type>一个是以下之一:
S = String
B = Boolean
b = Byte
c = Character
d = Double
f = Float
i = Integer
l = Long
s = Short
Run Code Online (Sandbox Code Playgroud)
这里有一些例子:
启动应用:
<a href="intent://#Intent;scheme=http;package=com.example.myapp;end">
Run Code Online (Sandbox Code Playgroud)
使用一个名为"foo"的字符串额外启动app,其中包含值"bar123":
<a href="intent://#Intent;scheme=http;package=com.example.myapp;S.foo=bar123;end">
Run Code Online (Sandbox Code Playgroud)
使用包含值"bar123"的名为"foo"的字符串extra和使用包含值"-567"的名为"number"的Integer extra启动应用程序:
<a href="intent://#Intent;scheme=http;package=com.example.myapp;S.foo=bar123;i.number=-567;end">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2995 次 |
| 最近记录: |