Home » » Check and request to install Facebook App

Check and request to install Facebook App

Written By MR HARI on Kamis, 06 Desember 2012 | 12.18

Last exercise "Start facbook app by startActivity(intent)", without checking if Facebook App installed. To check if a app installed currently, we can call getPackageManager().getApplicationInfo() method; if not installed, NameNotFoundException will be thrown. To open Google Play with with a specified app, startActivity with action of Intent.ACTION_VIEW and url of the target package.

Check and request to install Facebook App


Modify btnStartFacebookOnClickListener from the last exercise:
 OnClickListener btnStartFacebookOnClickListener
= new OnClickListener(){

@Override
public void onClick(View v) {

String facebookPackageName = "com.facebook.katana";
String facebookClassName = "com.facebook.katana.LoginActivity";

try {
ApplicationInfo facebookAppInfo = getPackageManager()
.getApplicationInfo(facebookPackageName, 0);
Intent intent = new Intent("android.intent.category.LAUNCHER");
intent.setClassName(facebookPackageName, facebookClassName);
startActivity(intent);
} catch (NameNotFoundException e) {
// Didn't installed
Toast.makeText(getApplicationContext(), "Facebook not found! INSTALL.", Toast.LENGTH_LONG).show();

//Start Market to downoad and install Facebook App
Uri uri = Uri.parse("market://details?id=" + facebookPackageName);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}

}};


Next:
- Launch Facebook app from a specified page, using intent with ACTION_VIEW.

Share this article :

0 komentar:

Posting Komentar

 
Support : Your Link | Your Link | Your Link
Copyright © 2013. Android Center - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger