我正在尝试使用URL打开一个Android应用程序,应用程序之前在所有其他设备上正常工作,但它不适用于三星galaxy tab 10“。
Heres My Code:
<intent-filter>
<data
android:host="com.magzine.nu"
android:scheme="magzine" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
并使用此 “MAGZINE://com.magzine.nu/马吉德= 532&安培; issueid = 7474” url打开应用程序,但是当点击URL时出现空白屏幕并消失,而不是打开应用程序,任何建议都将不胜感激。提前致谢。
答案 0 :(得分:1)
其他方法,你可以在你的网址中使用这样的Android Intents:
<a href="intent://read/#Intent;scheme=magzine;package=com.magzine.nu;end"> Will open magzine app</a>
然后像这样设置清单
<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="magzine" android:host="read" android:path="/"/>
</intent-filter>
如需更完整的参考,请查看Zxing manifest(Google推荐)
然后,对于解析部分,您可以查看Intent Source Code
特别是这部分:
/**
* Convert this Intent into a String holding a URI representation of it.
* The returned URI string has been properly URI encoded, so it can be
* used with {@link Uri#parse Uri.parse(String)}. The URI contains the
* Intent's data as the base URI, with an additional fragment describing
* the action, categories, type, flags, package, component, and extras.
*
* <p>You can convert the returned string back to an Intent with
* {@link #getIntent}.
*
* @param flags Additional operating flags. Either 0 or
* {@link #URI_INTENT_SCHEME}.
*
* @return Returns a URI encoding URI string describing the entire contents
* of the 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;");
toUriInner(uri, scheme, flags);
if (mSelector != null) {
uri.append("SEL;");
// Note that for now we are not going to try to handle the
// data part; not clear how to represent this as a URI, and
// not much utility in it.
mSelector.toUriInner(uri, null, flags);
}
uri.append("end");
return uri.toString();
}
答案 1 :(得分:0)
就我而言,每次都会编写一个代码来从后台打开应用程序,这会导致应用程序在打开后立即关闭,并给人一种应用程序未打开的印象。删除该代码后,它工作正常。所以上面的代码适合我的情况。 @NikoYuwono提到的方法也更值得推荐。