Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Eclipse Collections Categorically: Level up your programming game
this week in the
Open Source Projects
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Android
Android - How do I share to facebook app, if installed. Otherwise via web facebook (which I know how
Andrew Tyrer
Greenhorn
Posts: 8
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
So far in Android I know how to wall post to the user's wall via the web but I'd like, the app to detect whether the user has the facebook application installed and if so post via that. Does anyone know how to do this?
My code so far is below:
public class MainActivity extends Activity { private static String FACEBOOK_APP_ID = "276023232498070"; private static final String[] PERMISSIONS = new String[] { "publish_stream","email","user_birthday","user_location" }; private Facebook facebook; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); facebook = new Facebook(FACEBOOK_APP_ID); Bundle parameters = new Bundle(); parameters.putString("app_id", "276023232498070"); parameters.putString("link", "https://play.google.com/store/apps/details?id=myappistasty"); parameters.putString("name", "This is the name of the link set in app."); parameters.putString("caption", "This is Text that is specified in bt the aoo"); parameters.putString("picture", "http://i.dailymail.co.uk/i/pix/2012/11/15/article-0-1609D0FF000005DC-373_964x641.jpg"); // Posting my message, maybe here i could add paramterers like icon and a link etc..? facebook.dialog(MainActivity.this, "feed", parameters,new PostDialogListener()); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); facebook.authorizeCallback(requestCode, resultCode, data); Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_LONG).show(); } public abstract class BaseDialogListener implements DialogListener { @Override public void onFacebookError(FacebookError e) { e.printStackTrace(); } @Override public void onError(DialogError e) { e.printStackTrace(); } @Override public void onCancel() { } } public class PostDialogListener extends BaseDialogListener { @Override public void onComplete(Bundle values) { final String postId = values.getString("post_id"); if (postId != null) { Log.e("","Message posted on the wall."); MainActivity.this.finish(); } else { Log.e("","No message posted on the wall."); MainActivity.this.finish(); } } } }
Ulf Dittmer
Rancher
Posts: 43081
77
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The FB app may have its own Intents you could use - check the FB developer site.
As to what apps are installed, this is a starting point:
PackageManager pm = getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo appInfo : packages) { Log.i(LOG_TAG, "Installed package :" + appInfo.packageName); Log.i(LOG_TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(appInfo.packageName)); appInfo.dump(new LogPrinter(Log.INFO, LOG_TAG), LOG_TAG); }
Skool. Stay in. Smartness. Tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
how to get progress bar after selecting a view
Speak(read) a text when app is launched
java code for speech to text
cannot display image captured
activity doesn't wait untill alertdialog completes
More...