以编程方式从 Google 驱动器下载 APK 不工作
Programmatically download APK from Google Drive doesn't work
通过urls在网上找到随机apk时,我可以成功下载并安装它们,提示用户是否要安装。但是,当我将相同的 apk 上传到 Google 驱动器,然后 运行 从 Google 驱动器下载 url 时,apk 不起作用。我在设备屏幕上看到 "There was a problem while parsing the package"。我放了一个日志来查看正在下载多少数据。从 google 驱动器下载的 apk 似乎几乎没有 apk 的大小。大约 50k 而不是 4MB。我在网上看到很多关于这个的问题,但是 none 已经谈到 Google 播放不发送完整文件。为了从 Google 驱动器下载完整的 apk,我是否遗漏了什么?这是代码,
private void downloadApk(){
// checkVersion();
String extStorageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
File folder = new File(extStorageDirectory);
folder.mkdirs();
File file = new File(folder, "app-debug.apk");
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
DownloadApkTask downloadApkTask = new DownloadApkTask(APKURL,file);
downloadApkTask.execute();
}
public class DownloadApkTask extends AsyncTask<String, Void, Void> {
String fileURL;
File directory;
public DownloadApkTask(String fileURL,File directory) {
this.fileURL = fileURL;
this.directory = directory;
}
@Override
protected Void doInBackground(String... params) {
Log.v("DO in Back started","Started");
try {
FileOutputStream f = new FileOutputStream(directory);
URL u = new URL(fileURL);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.connect();
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer)) > 0) {
Log.v("PROGREsS", String.valueOf(len1));
f.write(buffer, 0, len1);
}
f.close();
directory.setReadable(true,false);
} catch (Exception e) {
System.out.println("exception in DownloadFile: --------"+e.toString());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void stringReturn) {
super.onPostExecute(stringReturn);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/app-debug.apk");
Log.v("STARTING INSTALLATION","-----");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
}
}
据此page,应用安装出现解析错误
When you try to install an application suddenly a window pop-ups saying "there is a problem parsing the package" which means the application cannot be installed due to apk parser i.e. parsing issue.
There are several reasons why this parsing error occurs & definitely one of them is responsible for your parsing error:
- File may be downloaded incompletely.
- Application might be not suitable for your hardware or OS version.
- Due to security issue settings
- Corrupted APK file.
按照下面显示的步骤修复移动设备上的 android 解析错误:
Check Manifested app apk file.
- Change the
Andriomanifest.xml
file to its default setting & also check the name of that file. If the original name of the file is “aap.apk” & if you renamed it as "app1.apk" then also it might cause an error. If you have some knowledge of coding, look into the app code if there is some problem with coding.
Security settings.
- For the security purpose, the phone has an inbuilt setting that doesn't allow installing applications from a 3rd party provider other than mobile apps provided by play store. Don’t install an app from the non-trusted website. That might really risk your mobile.
Enable USB debugging.
- Go to the settings >> Scroll down then, at last, you will see option “About device” select it.
- Look for option “build number.”
- Tap on “Build number” for 7 times.
- You will see a message “you are now a developer.”
- Once you enable to go back to settings
- Choose “Developer options.”
- Tick mark "USB debugging."
Corrupted App file.
- The parse error may cause due to corrupted file too. In this case, download a new but complete APK file, & try again to install it again. This might help you.
Disable Antivirus.
- If you have installed applications like antivirus & cleaner apps, then this can also prevent some apps installation. This prevention is due to the safety purpose of the handset. They block suspicious downloads from non-trusted sites. If you really want to install that app then disable the antivirus temporarily.
Clear cache cookies of play store.
- Open google play store
- Select sidebar & choose option “settings.”
- In general settings, you will find out to “clear local search history.”
通过urls在网上找到随机apk时,我可以成功下载并安装它们,提示用户是否要安装。但是,当我将相同的 apk 上传到 Google 驱动器,然后 运行 从 Google 驱动器下载 url 时,apk 不起作用。我在设备屏幕上看到 "There was a problem while parsing the package"。我放了一个日志来查看正在下载多少数据。从 google 驱动器下载的 apk 似乎几乎没有 apk 的大小。大约 50k 而不是 4MB。我在网上看到很多关于这个的问题,但是 none 已经谈到 Google 播放不发送完整文件。为了从 Google 驱动器下载完整的 apk,我是否遗漏了什么?这是代码,
private void downloadApk(){
// checkVersion();
String extStorageDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
File folder = new File(extStorageDirectory);
folder.mkdirs();
File file = new File(folder, "app-debug.apk");
try {
file.createNewFile();
} catch (IOException e1) {
e1.printStackTrace();
}
DownloadApkTask downloadApkTask = new DownloadApkTask(APKURL,file);
downloadApkTask.execute();
}
public class DownloadApkTask extends AsyncTask<String, Void, Void> {
String fileURL;
File directory;
public DownloadApkTask(String fileURL,File directory) {
this.fileURL = fileURL;
this.directory = directory;
}
@Override
protected Void doInBackground(String... params) {
Log.v("DO in Back started","Started");
try {
FileOutputStream f = new FileOutputStream(directory);
URL u = new URL(fileURL);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.connect();
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer)) > 0) {
Log.v("PROGREsS", String.valueOf(len1));
f.write(buffer, 0, len1);
}
f.close();
directory.setReadable(true,false);
} catch (Exception e) {
System.out.println("exception in DownloadFile: --------"+e.toString());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void stringReturn) {
super.onPostExecute(stringReturn);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)+"/app-debug.apk");
Log.v("STARTING INSTALLATION","-----");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);
}
}
据此page,应用安装出现解析错误
When you try to install an application suddenly a window pop-ups saying "there is a problem parsing the package" which means the application cannot be installed due to apk parser i.e. parsing issue.
There are several reasons why this parsing error occurs & definitely one of them is responsible for your parsing error:
- File may be downloaded incompletely.
- Application might be not suitable for your hardware or OS version.
- Due to security issue settings
- Corrupted APK file.
按照下面显示的步骤修复移动设备上的 android 解析错误:
Check Manifested app apk file.
- Change the
Andriomanifest.xml
file to its default setting & also check the name of that file. If the original name of the file is “aap.apk” & if you renamed it as "app1.apk" then also it might cause an error. If you have some knowledge of coding, look into the app code if there is some problem with coding.Security settings.
- For the security purpose, the phone has an inbuilt setting that doesn't allow installing applications from a 3rd party provider other than mobile apps provided by play store. Don’t install an app from the non-trusted website. That might really risk your mobile.
Enable USB debugging.
- Go to the settings >> Scroll down then, at last, you will see option “About device” select it.
- Look for option “build number.”
- Tap on “Build number” for 7 times.
- You will see a message “you are now a developer.”
- Once you enable to go back to settings
- Choose “Developer options.”
- Tick mark "USB debugging."
Corrupted App file.
- The parse error may cause due to corrupted file too. In this case, download a new but complete APK file, & try again to install it again. This might help you.
Disable Antivirus.
- If you have installed applications like antivirus & cleaner apps, then this can also prevent some apps installation. This prevention is due to the safety purpose of the handset. They block suspicious downloads from non-trusted sites. If you really want to install that app then disable the antivirus temporarily.
Clear cache cookies of play store.
- Open google play store
- Select sidebar & choose option “settings.”
- In general settings, you will find out to “clear local search history.”