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.
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.
Related Posts :
Turning the page with a new Google Play Books app for AndroidGoogle Play Books enables you to read more than 4 million books on the go, and it's available in the U.S., Canada, Australia, Germany, Spain… Read More...
Bringing Google Calendar to the Play StorePosted by Michael Chan, Tech LeadPreviously available only on select Android devices like Nexus S and Galaxy Nexus, you can now download the… Read More...
Google Play hits 25 billion downloadsWhether you’re looking for directions, checking email or sharing a picture with friends, apps are now an indispensable part of life. And if … Read More...
Nexus: The best of Google, now in three sizesPeople increasingly have more than one device, and they switch between them many times a day. Nexus—Google’s hardware line for Android dev… Read More...
The Benefits & Importance of CompatibilityWe built Android to be an open source mobile platform freely available to anyone wishing to use it. In 2008, Android was released under the … Read More...
0 Response to "Check and request to install Facebook App"
Post a Comment