If you want to replace a third-party application icon with a theme made by an Android theme developer, you must know the package name of the application. In fact, it is very simple to know the package name of the application. Just open Google Play or Wandoujia in the browser, open the page of an application, and look at the URL. You will find that the last "/" character in the URL is followed by the package name of the application!
I guess someone wanted to get the icons and package names of commonly used applications, so I wrote a small program in Java to batch capture application icons and packages from pages 1 to 20 of "All Software" on Wandoujia, ranked by total downloads. name.
All icons are named with package names, and there is also a packageName.txt file inside, which contains the package name corresponding to the application name for easy search.
java source code
Share this java applet. Note that if the web page structure of Wandoujia changes (it probably rarely changes), this applet will need to be modified. If you can understand it, the modification is very simple.
The following code may no longer be valid and is for reference only!
Copy the code code as follows:
package im.garth.AppIconDownloader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map.Entry;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
* Get all the Android software on Wandoujia website
* Note: Before executing the program, be sure to create an icon folder in this project directory.
* All icons will be downloaded to the icon folder
* The application name and package name are written in the packageName.txt file under the icon
*
* Jar packages used in this program:
* commons-logging-1.1.3.jar
* httpclient-4.1.2.jar
* httpcore-4.3.jar
* jsoup-1.6.1.jar
*
*
*/
public class AppIconDownloader {
/**
* @param args
*/
public static void main(String[] args) {
String rootUrl = "http://www.wandoujia.com/tag/all software/total?page=";
//String rootUrl = "http://www.wandoujia.com/tag/allgames/total?page=";
//Download application icons from pages 1 to 20
for(int i = 1; i < = 20; i++) {
System.out.println("[Download progress]: Prepare to download page " + i + "");
String currentUrl = rootUrl + i;
HashMap<String, String> apps = new HashMap<string, String>();
apps = getAppImageUrl(currentUrl);
//Traverse the HashMap to download icons one by one
for(Entry</string><string , String> entry : apps.entrySet()) {
try{
//Download the icon and store it in the icon directory under the current project directory (please create the icon directory in advance)
download(entry.getValue(), "icon/" + entry.getKey() + ".png");
}catch(Exception e) {
System.out.println("[Download error]: " + entry.getKey());
e.printStackTrace();
}
}
System.out.println("[Download progress]: Page " + i + " download completed");
}
}
/**
* Get the application names and icon URLs of all applications in the url web page
* @param appPackageName
* @return
*/
private static HashMap</string><string, String> getAppImageUrl(String url) {
HashMap</string><string, String> apps = new HashMap</string><string, String>();
String appPackageName = "";
String appImageUrl = "";
String appName = "";
String html = getHtmlByUrl(url);
Document doc = Jsoup.parse(html);
Elements elements = doc.select("div.container.clearfix>section.main-col>div.app-blocks>div.app-block>ul.app-list.clearfix>li.app>a.icon-area" );
Elements nameElements = doc.select("div.container.clearfix>section.main-col>div.app-blocks>div.app-block>ul.app-list.clearfix>li.app>div.operate>a. name>span.txt");
Elements imageEle;
int i = 0;
for(Element ele : elements) {
//Get the package name
appPackageName = ele.attr("data-pn");
//Get the icon URL
imageEle = ele.select("img.icon");
appImageUrl = imageEle.get(0).attr("src").replace("68_68", "256_256");
//Add apps
apps.put(appPackageName, appImageUrl);
//Get the app name
appName = nameElements.get(i).text();
//Output the app name and package name to the file
write2file("【" + appName + "】" + appPackageName);
i++;
}
System.out.println("[Download Progress]:" + url + "The icon URL under "has been obtained successfully");
return apps;
}
/**
* Download files to local
*
* @param urlString
* Downloaded file address
* @param filename
* Local file name
* @throwsException
* Various abnormalities
*/
private static void download(String urlString, String filename) throws Exception {
System.out.println("[Download progress]: Downloading" + filename);
// Construct URL
URL url = new URL(urlString);
//Open connection
URLConnection con = url.openConnection();
// input stream
InputStream is = con.getInputStream();
// 1K data buffer
byte[] bs = new byte[1024];
//The length of data read
int len;
//Output file stream
OutputStream os = new FileOutputStream(filename);
// Start reading
while ((len = is.read(bs)) != -1) {
os.write(bs, 0, len);
}
// Done, close all links
os.close();
is.close();
System.out.println("[Download progress]:" + filename + "Download successful");
}
/**
* Get all html information based on URL
* @param url
* @return html
*/
private static String getHtmlByUrl(String url){
String html = null;
//Create httpClient object
HttpClient httpClient = new DefaultHttpClient();
//Request the URL in get mode
HttpGet httpget = new HttpGet(url);
try {
//Get the response object
HttpResponse response = httpClient.execute(httpget);
//return code
int resStatu = response.getStatusLine().getStatusCode();
//200 is normal, others are incorrect
if (resStatu==HttpStatus.SC_OK) {
//Get the corresponding entity
HttpEntity entity = response.getEntity();
if (entity!=null) {
//Get html source code
html = EntityUtils.toString(entity);
}
}
} catch (Exception e) {
System.out.println("Exception occurred while accessing ["+url+"]!");
e.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}
return html;
}
private static void write2file(String content) {
File file = new File("icon/packageName.txt");
BufferedWriter writer = null;
try{
if(!file.exists()) {
file.createNewFile();
}
//Parameter true means appending the output to the end of the file content without overwriting the original content.
writer = new BufferedWriter(new FileWriter(file, true));
//output content
writer.write(content);
//Newline
writer.newLine();
} catch(IOException e){
System.out.println("Output error");
e.printStackTrace();
} finally {
if( writer != null) {
try {
writer.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
}
}