获取 phone 中安装的所有社交媒体应用程序的列表?

Get list of all social media application installed in phone?

我正在开发一个应用程序,其中列出了安装在用户手机中的所有应用程序。我检索了所有应用程序并将其列在 RecyclerView 中。现在我想出于其他目的将社交媒体应用程序从该列表中分离出来。有什么方法可以分离社交媒体应用程序吗? 我正在使用以下代码从 phone.

检索所有应用程序包名称
public List<String> GetAllInstalledApkInfo(){

    List<String> ApkPackageName = new ArrayList<>();

    Intent intent = new Intent(Intent.ACTION_MAIN,null);

    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED );

    List<ResolveInfo> resolveInfoList = context1.getPackageManager().queryIntentActivities(intent,0);

    for(ResolveInfo resolveInfo : resolveInfoList){

        ActivityInfo activityInfo = resolveInfo.activityInfo;

        ApkPackageName.add(activityInfo.applicationInfo.packageName);
    }

    return ApkPackageName;

}

如果你得到每个应用程序的包名,你可以直接询问 play store 一个应用程序属于哪个类别,用这个库解析 html 响应页面:

org.jsoup.jsoup1.8.3

这里有一个片段可以解决您的问题:

public class MainActivity extends AppCompatActivity {

public final static String GOOGLE_URL = "https://play.google.com/store/apps/details?id=";
public static final String ERROR = "error";

...


   private class FetchCategoryTask extends AsyncTask<Void, Void, Void> {

       private final String TAG = FetchCategoryTask.class.getSimpleName();
       private PackageManager pm;
       private ActivityUtil mActivityUtil;

       @Override
       protected Void doInBackground(Void... errors) {
          String category;
           pm = getPackageManager();
           List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
           Iterator<ApplicationInfo> iterator = packages.iterator();
           while (iterator.hasNext()) {
               ApplicationInfo packageInfo = iterator.next();
               String query_url = GOOGLE_URL + packageInfo.packageName;
               Log.i(TAG, query_url);
               category = getCategory(query_url);
               // store category or do something else
           }
           return null;
        }


        private String getCategory(String query_url) {
           boolean network = mActivityUtil.isNetworkAvailable();
           if (!network) {
               //manage connectivity lost
               return ERROR;
           } else {
               try {
                   Document doc = Jsoup.connect(query_url).get();
                   Element link = doc.select("span[itemprop=genre]").first();
                   return link.text();
               } catch (Exception e) {
                   return ERROR;
               }
           }
        }
    }  
}