안녕하세요. 2 주 후에 다시이 연구에 착수하여이 오류로 어려움을 겪었습니다. * 구문 분석 오류 : * 패키지 분석 문제가 있습니다.다운로드 한 .apk 파일을 설치하는 동안 구문 분석 오류가 발생했습니다.
내가 구현 한 범위는 업데이트 된 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);
}
메인 스레드의 네트워크에서 자료를 다운로드하고 있습니다. 이 작업을 수행하지 마십시오. IntentService를 살펴보십시오. 백그라운드 스레드에서 작업을 실행하는 서비스입니다. –
그래서 서비스의 권리가 아닌 IntentSevice를 확장하려고합니다. – Thamilvanan