Get all Twitter clients from installed applications

I am wondering if it is possible to list all the Twitter clients that are installed on the phone. At first I thought that this could be done by matching the package name with Twitter. But most Twitter clients on Android do not have the name “Twitter” in the name of their package.

We can get a list of applications with specific permissions, but that will not help me. Retrieving applications with specific user intentions probably won't help either, and I still need to find a way to get a list of applications that handle user-generated intent.

This is not possible, but there must be some way that could at least put me close to the desire that I want. Would anyone like to shed light on him?

+4
source share
1 answer

I don’t know if there is any method for getting a twitter client (how do we define a twitter client?).
You can get a list of names (twitter clients you know) on packages installed on devices.

final List<PackageInfo> apps = context.getPackageManager().getInstalledPackages(0);
final String separator = ";";
final String separatorVersion = "-";

//Log.i("Package list", "num:+"+apps.size());
for (PackageInfo infoApp : apps) {
    for (TwitterClient tr : mapTwitterClient.values()) {
        if (infoApp.packageName.contains(tr.getPackageName()) ) { //it a Twitter client this package?
            if (!twitterClients.equals("")) {
                twittersClients += separator;
            }
            twitterClients += tr.getCommonName()+separatorVersion+infoApp.versionName;
        }
    }
}

You need to create a TwitterClient class that has only 2 properties (package name and commonName) and its recipients / setters.

And fill the map with all your TwitterClient (Ex:) new TwitterClient("com.twitter.android","Twitter official");

private static final HashMap<String, TwitterClient> mapTwitterClient

This method requires complex use.

0
source

Source: https://habr.com/ru/post/1535558/


All Articles