How to ask if foursquare is installing in the phone and how to open foursquare in android code?

StackOverflow https://stackoverflow.com/questions/22761008

  •  24-06-2023
  •  | 
  •  

Question

I don't know how to ask if foursquare is installing in the phone and how to open foursquare.

I have this code in iPhone but now I don't know how to do in android. My code in objective-c is this: NSString *urlSTR = [NSString stringWithFormat:@"foursquare://venues/%@", venueID]; NSURL *openFoursquare = [NSURL URLWithString:urlSTR]; if ( ![[UIApplication sharedApplication] openURL:openFoursquare] ) { urlSTR = [NSString stringWithFormat:@"https://es.foursquare.com/v/%@", venueID]; openFoursquare = [NSURL URLWithString:urlSTR]; [[UIApplication sharedApplication] openURL:openFoursquare]; }

Any idea? I hope that somebody help me.

Was it helpful?

Solution

Try the following

try {
    startActivity(intent);          
} catch (ActivityNotFoundException e) {
    // Activity not found, app not installed!
}

Or you can ask the PackageManager if the package is installed with the following:

private boolean isPackageInstalled(String packagename, Context context) {   
    PackageManager pm = context.getPackageManager();
    try {
        pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top