我正在尝试使用我的 PhoneGap 应用程序链接来打开 Twitter 应用程序中的特定用户个人资料页面。我知道不是每个人都在他们的设备上安装了 Twitter 应用程序,所以如果他们没有,我想将他们发送到 Play 商店下载。
问题是,每次我在我的 Android 设备上点击链接时,我都会收到错误消息:
Application Error:
net::ERR_UNKNOWN_URL_SCHEME(twitter://user?screen_name=xerxesnoble)
我的 JavaScript 如下:
//If Android
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if (isAndroid) {
alert('Android!');
twitterCheck = function() {
alert('Android!');
var now = new Date().valueOf();
setTimeout(function () {
if (new Date().valueOf() - now > 100) return;
window.open('https://play.google.com/store/apps/details?id=com.twitter.android', '_system', 'location=no');
}, 50);
window.open('twitter://user?screen_name=XerxesNoble', '_system', 'location=no');
};
};
$('.twiterNav').click(function() {
window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');
});
我尝试过的事情:
- 使用
twitter:///
而不是twitter://
- 正在添加
<access origin="twitter://user?screen_name=xerxesnoble" />
到我的config.xml
我不确定还能尝试什么,Facebook 也没有任何效果,但现在我一次只关注一个问题。
最佳答案
问题是未安装 InAppBrowser 插件。 PhoneGap/Cordova 的新版本并没有安装所有插件——而是您选择您希望您的应用程序访问的内容。
在终端 cd yourApp
和 $ cordova plugin add org.apache.cordova.inappbrowser
这样做之后,它就完美地工作了。
编辑
只是进一步说明我是如何让我的 .js 检查是否安装了 twitter 的。
我安装了另一个插件:AppAvailability for iOS and Android
然后我将我的 .js 修改为如下所示:
//Twitter checker
// If Mac//
var twitterCheck = function(){
appAvailability.check('twitter://', function(availability) {
// availability is either true or false
if(availability) { window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
else{window.open('https://itunes.apple.com/ca/app/twitter/id333903271?mt=8', '_system', 'location=no'); };
});
};
//If Android
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
twitterCheck = function(){
appAvailability.check('com.twitter.android', function(availability) {
// availability is either true or false
if(availability) {window.open('twitter://user?screen_name=xerxesnoble', '_system', 'location=no');}
else{window.open('https://play.google.com/store/apps/details?id=com.twitter.android', '_system', 'location=no');};
});
};
};
AppAvailability 插件中提供的文档也非常有帮助>
希望这对某人有帮助!
关于javascript - 如何使用 Phonegap 打开 Twitter 和 Facebook 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23095906/