如何使用 nanohttpd 下载已安装的应用程序
How download an installed app with nanohttpd
你好,我想用 nanohttpd 制作一个 http 服务器,显示已安装的应用程序,并将它们转换为 apk 并下载。我可以列出,但如何下载我的应用程序 select
List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA;
for (ApplicationInfo packageInfo : packages) {
String name = String.valueOf(packageManager.getApplicationLabel(packageInfo));
if (name.isEmpty()) {
name = packageInfo.packageName;
}
Drawable icon = packageManager.getApplicationIcon(packageInfo);
String apkPath = packageInfo.sourceDir;
apps.add(new App(name, apkPath, icon, packageInfo.packageName));
}
if (method.equals(Method.GET)) {
for (App file : apps) {
answer += "<a href=\"" + file.getAppName()
+ "\" alt = \"\">" + file.getAppName()
+ "</a><br>";
}
好的,我基本上是在列出应用程序后使用 url 并检查哪个应用程序名称等于 url 然后我开始像那样下载它
if (method.equals(Method.GET)) {
if (a) {
answer = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; " +
"charset=utf-8\"><title> HTTP File Browser</title>";
for (App file : appShare) {
answer += "<a href=\"" + file.getAppName()
+ "\" alt = \"\">" + file.getAppName()
+ "</a><br>";
}
answer += "</head></html>";
if(blabla.equals(header.get("referer"))){
a=false;
}
} else {
for (int i = 0; i < appShare.size(); i++) {
if (appShare.get(i).getAppName().equals(appnames))
arrayC = i;
}
answer = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; " +
"charset=utf-8\"><title> Download " + appShare.get(arrayC).getAppName() + "</title>";
// serve file download
InputStream inputStream;
Response response = null;
if (mStatusUpdateListener != null) {
mStatusUpdateListener.onDownloadingFile(
new File(appShare.get(arrayC).getApkPath()), false);
}
try {
inputStream = new FileInputStream(
new File(appShare.get(arrayC).getApkPath()));
response = new DownloadResponse(
new File(appShare.get(arrayC).getApkPath()), inputStream);
} catch (Exception e) {
e.printStackTrace();
} response.addHeader(
"Content-Disposition", "attachment; filename=" + appShare.get(arrayC).getAppName()+".apk");
return response;
}
你好,我想用 nanohttpd 制作一个 http 服务器,显示已安装的应用程序,并将它们转换为 apk 并下载。我可以列出,但如何下载我的应用程序 select
List<ApplicationInfo> packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA;
for (ApplicationInfo packageInfo : packages) {
String name = String.valueOf(packageManager.getApplicationLabel(packageInfo));
if (name.isEmpty()) {
name = packageInfo.packageName;
}
Drawable icon = packageManager.getApplicationIcon(packageInfo);
String apkPath = packageInfo.sourceDir;
apps.add(new App(name, apkPath, icon, packageInfo.packageName));
}
if (method.equals(Method.GET)) {
for (App file : apps) {
answer += "<a href=\"" + file.getAppName()
+ "\" alt = \"\">" + file.getAppName()
+ "</a><br>";
}
好的,我基本上是在列出应用程序后使用 url 并检查哪个应用程序名称等于 url 然后我开始像那样下载它
if (method.equals(Method.GET)) {
if (a) {
answer = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; " +
"charset=utf-8\"><title> HTTP File Browser</title>";
for (App file : appShare) {
answer += "<a href=\"" + file.getAppName()
+ "\" alt = \"\">" + file.getAppName()
+ "</a><br>";
}
answer += "</head></html>";
if(blabla.equals(header.get("referer"))){
a=false;
}
} else {
for (int i = 0; i < appShare.size(); i++) {
if (appShare.get(i).getAppName().equals(appnames))
arrayC = i;
}
answer = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; " +
"charset=utf-8\"><title> Download " + appShare.get(arrayC).getAppName() + "</title>";
// serve file download
InputStream inputStream;
Response response = null;
if (mStatusUpdateListener != null) {
mStatusUpdateListener.onDownloadingFile(
new File(appShare.get(arrayC).getApkPath()), false);
}
try {
inputStream = new FileInputStream(
new File(appShare.get(arrayC).getApkPath()));
response = new DownloadResponse(
new File(appShare.get(arrayC).getApkPath()), inputStream);
} catch (Exception e) {
e.printStackTrace();
} response.addHeader(
"Content-Disposition", "attachment; filename=" + appShare.get(arrayC).getAppName()+".apk");
return response;
}