In my project i want to connect my app with twitter. It will first check if twitter app is present on user's device if yes it will take credential from there only else this button will be disabled.
suggest me.
You can use this to check if the official Twitter application is installed:
PackageManager pkManager = activity.getPackageManager();
try {
PackageInfo pkgInfo = pkManager.getPackageInfo("com.twitter.android", 0);
String getPkgInfo = pkgInfo.toString();
if (getPkgInfo.equals("com.twitter.android")) {
// APP NOT INSTALLED
}
} catch (NameNotFoundException e) {
e.printStackTrace();
// APP NOT INSTALLED
}
However, even if it is installed, you will not be able to pull out any credentials from it to use within your own app. You will need to the Twitter4J library to manage user authentication within your own app. Pulling out data from the app, if it were installed, is just not an option.
try{
ApplicationInfo info = getPackageManager().
getApplicationInfo("com.twitter.android", 0 );
return true;
} catch( PackageManager.NameNotFoundException e ){
return false;
}
this will check if the official app for Twitter
is installed or not
boolean twitterInstalled = false;
try{
ApplicationInfo info = getPackageManager().
getApplicationInfo("com.twitter.android", 0 );
twitterInstalled = true;
} catch( PackageManager.NameNotFoundException e ){
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With