用例:我需要复制流行的社交网络用来提供指向给定内容的链接的方式,例如帖子。这意味着像 https://www.example.com/link-to-the-content 这样的链接应该被代号一应用程序的Android,iOS和Javascript端口拦截。
我试图这样做,但没有成功。
Javascript 端口我不知道Display.getInstance().getProperty("AppArg", null);
是否在javascript 端口中以任何方式实现。我知道如果 javascript 端口安装在 https://www.example.com/中,那么 https://www.example.com/link-to-the-content 会产生 404 错误。但是,我想可以通过实现一些服务器代码(可以自动包含在构建服务器生成的war
中(来规避此限制......或者,没有任何特殊的服务器代码,如果URL像 https://www.example.com/?content=xyz,也许可以使用Display.getInstance().getProperty("AppArg", null);
。如果有任何已经有效的解决方案或是否需要 RFE,请告诉我。
安卓端口这部分对我有用,我的代码有问题吗?问题是,如果应用程序被杀死然后从链接打开,它工作正常,但如果应用程序从图标打开,然后在后台放置,然后从链接再次打开,则它不起作用:在这种情况下,应用程序将显示空白的白屏。
我的安卓构建提示:android.xintent_filter=<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:host="example.com" android:scheme="https" /></intent-filter>
法典:
public class MyApplication {
private Form current;
private Resources theme;
private String arg;
public void init(Object context) {
[...]
}
public void start() {
if (current != null) {
current.show();
return;
}
Form hi = new Form("Hi World", BoxLayout.y());
final SpanLabel message;
arg = Display.getInstance().getProperty("AppArg", null);
if (arg == null) {
message = new SpanLabel("App launched from icon");
} else {
message = new SpanLabel("App launched from the url: " + arg);
}
hi.add(message);
hi.show();
hi.addShowListener(l -> {
arg = Display.getInstance().getProperty("AppArg", null);
if (arg == null) {
message.setText("App launched from icon");
} else {
message.setText("App launched from the url: " + arg);
}
hi.revalidate();
});
}
iOS端口这对我来说根本不起作用。我尝试使用构建提示ios.urlScheme=<string>example.com</string>
,但像 https://www.example.com/link-to-the-content 这样的网址没有被拦截。我猜ios.urlScheme=<string>example.com</string>
用于指定协议而不是域,但我不知道我必须编写哪个构建提示才能拦截具有给定域的任何 url。
在Android和iOS中,您需要自定义URL方案,例如,这些是代号One Build应用程序的构建提示:
android.xintent_filter=<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="cn1bldapp" /> </intent-filter>
ios.plistInject=<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>com.codename1.build.app</string> </dict> <dict> <key>CFBundleURLSchemes</key> <array> <string>cn1bldapp</string> </array> </dict> </array>
对于这些构建提示,您可以使用如下所示的 URL:
cn1bldapp://content-of-the-url
不幸的是,这只能部分工作,因为大多数地方不会将cn1bldapp识别为URL。但正如我在这里解释的那样,这里有一个技巧,你可以使用 https URL,然后使用 302 响应重定向到 cn1bldapp。这样,您还可以检测引用调用方,并在它们不同时发送正确的 URL 响应。
关于 JavaScript 端口,我认为您可能可以使用#
选项传递 URL 参数,然后使用该位置在 JS 中查询该参数,但可能有更优雅的方法来传递它或进行深度链接。我得检查一下。