Android Categorize Installed Applications
Solution 1:
Use the WhereDat API:
Create a rawJSON POST request, with an array of the packages you want to categorize:
{"packages":["com.pixmix.mobileapp","com.nextstagesearch"]}
Send it to:
http://api.wheredatapp.com/data
And here's the response:
{"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..."}]}
Solution 2:
try it, it works perfectly for me. these codes returns category of all app in recent device. Remember you have to put these code into a thread (AsyncTask...) (HttpParams is deprecated, we should use HttpUrlConnection instead).
privatevoidgetAppCategories()throws IOException, JSONException {
BufferedReaderbufferedReader=null;
HttpURLConnectionurlConnection=null;
BufferedWriterbufferedWriter=null;
StringBuilderresult=newStringBuilder();
//Create JSON object to send to webserviceJSONObjectjsonObjectSend=newJSONObject();
JSONArrayjsonArrayPakages=newJSONArray();
PackageManager packageManager;
List<ResolveInfo> listApps; //this list store all app in devicetry {
packageManager = getPackageManager();
IntentfilterApp=newIntent(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());
URLurl=newURL("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();
OutputStreamoutputStream= urlConnection.getOutputStream();
bufferedWriter = newBufferedWriter(newOutputStreamWriter(outputStream));
bufferedWriter.write(jsonObjectSend.toString());
bufferedWriter.flush();
InputStreaminputStream= urlConnection.getInputStream();
bufferedReader = newBufferedReader(newInputStreamReader(inputStream));
//Read data
String line;
while ((line = bufferedReader.readLine()) != null) {
result.append(line);
}
/*Parse JSON**********************************************************************************/JSONObjectjsonObjectResult=newJSONObject(result.toString().trim());
JSONArrayjsonArrayApps= jsonObjectResult.getJSONArray("apps");
for (intj=0; j < jsonArrayApps.length(); j++) {
JSONObjectjsonObjectApp= jsonArrayApps.getJSONObject(j);
StringpackageName= jsonObjectApp.getString("package").trim();
Stringcate= 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();
}
}
}
call this method under AsyncTask:
new AsyncTask<Void, Void, Void>() {
@OverrideprotectedVoid 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);
}
returnnull;
}
}.execute();
and DO NOT forget INTERNET permission.
<uses-permissionandroid:name="android.permission.INTERNET"></uses-permission>
Solution 3:
Android or playstore not providing the direct APIs for accessing Application (Category) information from playstore programmatically. So there is no official APIs.
http://wheredatapp.com/developers/ this API also not giving the 100% results. (these people are doing manually. Just visit playstore and know the category and package name, then those details stored into their own server).So that this API also not giving the all applications information from play store.
This way we will also doing. there is no issue. but it takes some time.
Post a Comment for "Android Categorize Installed Applications"