Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check to see if twitter app is present on user's device

Tags:

android

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.

like image 755
Avinash Kumar Pankaj Avatar asked May 16 '13 10:05

Avinash Kumar Pankaj


3 Answers

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.

like image 160
Siddharth Lele Avatar answered Nov 03 '22 23:11

Siddharth Lele


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

like image 3
Syn3sthete Avatar answered Nov 03 '22 23:11

Syn3sthete


boolean twitterInstalled = false;

    try{
        ApplicationInfo info = getPackageManager().
                getApplicationInfo("com.twitter.android", 0 );
        twitterInstalled = true;
    } catch( PackageManager.NameNotFoundException e ){
    }
like image 1
Alexis C. Avatar answered Nov 03 '22 23:11

Alexis C.