Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  132] [ 4]  / answers: 1 / hits: 14223  / 10 Years ago, tue, april 15, 2014, 12:00:00

I am trying to have my PhoneGap application link to open a specific users profile page in the Twitter app. I know not everyone has the Twitter app installed on their device so I wanted to send them to the Play Store to download it if they didn't.



Problem is that every time I tap the link on my Android device I receive an error:



Application Error:

net::ERR_UNKNOWN_URL_SCHEME(twitter://user?screen_name=xerxesnoble)


My JavaScript is as follows:



//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');
});


Things that I've tried:




  • Using twitter:/// instead of twitter://

  • Adding <access origin=twitter://user?screen_name=xerxesnoble /> to my config.xml



I'm not sure what else to try, nothing is working for Facebook either but right now I'm focusing on one issue at a time.


More From » android

 Answers
2

The Problem is that the InAppBrowser plugin was not installed. New versions of PhoneGap/Cordova do not come with all plugins installed- instead you choose what you want your App to have access to.



In terminal cd yourApp and $ cordova plugin add org.apache.cordova.inappbrowser



After doing that, it worked perfectly.



EDIT



Just to branch out a little bit more on how I got my .js to check if twitter was installed or not.



I installed another plugin : AppAvailability for iOS and Android



Then I altered my .js to look like this:



//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');};
});
};
};


The documentation provided in the AppAvailability plugin was very helpful as well>



Hope that this helps someone!


[#45991] Tuesday, April 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myakylas

Total Points: 66
Total Questions: 85
Total Answers: 95

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
myakylas questions
Thu, Apr 28, 22, 00:00, 2 Years ago
Thu, Apr 8, 21, 00:00, 3 Years ago
Sat, Sep 19, 20, 00:00, 4 Years ago
;