嗨,两周后,我再次开始研究并努力解决这个错误*解析错误: *解析包有问题。
我的实施范围是尝试从我有更新的 apk 文件的服务器更新我的应用程序,并使用服务通过我的应用程序下载它。现在我可以从该服务器下载文件我可以手动安装它。但我的范围就像从服务器下载文件后它应该自动调用安装应用程序弹出窗口。安装时出现上述错误。我在问这个问题之前尝试过谁在这里问过同样的问题.
这是我的代码:
public class Myservice extends Service {
String versionName;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
}
@Override
public void onDestroy() {
Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startid) {
try {
versionName = getPackageManager().getPackageInfo(getPackageName(),
0).versionName;
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DownloadFromUrl();
}
public void DownloadFromUrl() { //this is the downloader method
try {
URL url = new URL("http://61.12.5.34:10140/test/UpateTest.apk");
String file ="YeldiUpateTest.apk";
long startTime = System.currentTimeMillis();
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
/*
* Read bytes to the Buffer until there is nothing more to read(-1).
*/
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
/* Convert the Bytes read to a String. */
FileOutputStream fos = openFileOutput(file, Context.MODE_PRIVATE);
Log.v("wsd", "write");
fos.write(baf.toByteArray());
fos.close();
Log.d("Download time", "download ready in"
+ ((System.currentTimeMillis() - startTime) / 1000)
+ " sec");
install();
} catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}
这是我的安装方法():
void install()
{
File path=getFileStreamPath("UpateTest.apk");
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(path), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}