我想对已安装的 android 应用程序(如社交、娱乐、游戏、新闻、工具等)进行分类。谁能建议我如何以编程方式安排所有已安装的应用程序?
问问题
1100 次
3 回答
2
使用WhereDat API:
创建一个原始 JSON POST请求,其中包含要分类的包数组:
{
"packages": [
"com.pixmix.mobileapp",
"com.nextstagesearch"
]
}
发送至:
http://api.wheredatapp.com/data
这是回应:
{
"apps": [
{
"category": "Productivity",
"rating": 4.5,
"updated": 1436741473,
"created": 1431028391,
"icon_url": "https://lh3.googleusercontent.com/q5pFGfXKZejowwcmlJl7M1IXGHVM4Zq_IjPpYb7zgkUFXO3QnZ2LyeOUUhMPaKPkJ3gR=w300",
"title": "WhereDat Beta",
"package": "com.nextstagesearch",
"ratings_count": 4,
"short_description": "WhereDat lets you easily search your device for contacts, apps, and recently accessed webpages without leaving your home screen. With deep linking you can search the c..."
},
{
"category": "Photography",
"rating": 4.0519609451293945,
"updated": 1435970764,
"created": 1430868349,
"icon_url": "https://lh3.ggpht.com/NgbwQzyo2mDR8su1Embio5jtHuPyScaMr0j4iub58YR5m19Ns0gVdeb9pYgNvMuFCcg=w300",
"title": "PixMix - Photo sharing",
"package": "com.pixmix.mobileapp",
"ratings_count": 2040,
"short_description": "Simple collage or photo sharing in just two clicks!★ See your photos in BEAUTIFUL albums★ Create beautiful album COLLAGE★ EASILY send albums to friends and family★ You..."
}
]
}
于 2015-05-06T01:23:37.380 回答
2
试试看,它对我来说非常有效。这些代码返回最近设备中所有应用程序的类别。请记住,您必须将这些代码放入一个线程(AsyncTask...)(不推荐使用 HttpParams,我们应该改用 HttpUrlConnection)。
private void getAppCategories() throws IOException, JSONException {
BufferedReader bufferedReader = null;
HttpURLConnection urlConnection = null;
BufferedWriter bufferedWriter = null;
StringBuilder result = new StringBuilder();
//Create JSON object to send to webservice
JSONObject jsonObjectSend = new JSONObject();
JSONArray jsonArrayPakages = new JSONArray();
PackageManager packageManager;
List<ResolveInfo> listApps; //this list store all app in device
try {
packageManager = getPackageManager();
Intent filterApp = new Intent(Intent.ACTION_MAIN);
filterApp.addCategory(Intent.CATEGORY_LAUNCHER);
listApps = packageManager.queryIntentActivities(filterApp,
PackageManager.GET_META_DATA);
for (ResolveInfo app : listApps) {
jsonArrayPakages.put(app.activityInfo.packageName.trim());
}
jsonObjectSend.put("packages", jsonArrayPakages);
Log.d("json", jsonObjectSend.toString());
URL url = new URL("http://getdatafor.appspot.com/data?key=53972606b926d38191a5446fdff89e377873d767fabedf6d");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(10000); /* milliseconds */
urlConnection.setReadTimeout(10000); /* milliseconds */
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type", "application-json");
urlConnection.setDoOutput(true); /* allow output to send data */
urlConnection.connect();
OutputStream outputStream = urlConnection.getOutputStream();
bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
bufferedWriter.write(jsonObjectSend.toString());
bufferedWriter.flush();
InputStream inputStream = urlConnection.getInputStream();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//Read data
String line;
while ((line = bufferedReader.readLine()) != null) {
result.append(line);
}
/*Parse JSON**********************************************************************************/
JSONObject jsonObjectResult = new JSONObject(result.toString().trim());
JSONArray jsonArrayApps = jsonObjectResult.getJSONArray("apps");
for (int j = 0; j < jsonArrayApps.length(); j++) {
JSONObject jsonObjectApp = jsonArrayApps.getJSONObject(j);
String packageName = jsonObjectApp.getString("package").trim();
String cate = jsonObjectApp.getString("category").trim();
Log.d("result", (j + 1) + "---> : " + packageName + "---" + cate);
}
/***********************************************************************************/
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
if (bufferedWriter != null) {
bufferedWriter.close();
}
if (urlConnection != null) {
urlConnection.disconnect();
}
}
}
在 AsyncTask 下调用此方法:
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
try {
getAppCategories();
} catch (IOException e) {
Log.d("tag", "Net work error: " + e.getMessage(), e);
} catch (JSONException e) {
Log.d("tag", "JSON is not valid: " + e.getMessage(), e);
}
return null;
}
}.execute();
并且不要忘记互联网许可。
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
于 2015-08-15T10:39:42.883 回答
0
Android 或 Playstore 未提供用于以编程方式从 Playstore 访问应用程序(类别)信息的直接 API。所以没有官方的API。
http://wheredatapp.com/developers/ 这个 API 也没有给出 100% 的结果。(这些人是手动做的。只需访问 playstore 并知道类别和包名称,然后将这些详细信息存储到他们自己的服务器中)。因此该 API 也不会提供来自 play store 的所有应用程序信息。
这种方式我们也会这样做。没有问题。但这需要一些时间。
于 2016-09-23T13:31:50.933 回答