0

Google Playストア以外のAndroidにアップデートをダウンロードしてインストールしようとしています。 このチュートリアルをガイドとして使用しています(http://simpledeveloper.com/how-to-update-android-apk-outside-the-playstore/)Googleドライブから自分のアプリケーション用のapkファイル(アップデートがある)をダウンロードするために私のアプリケーションにコードを挿入しました。Androidのエラー解析パッケージ - 部分的なダウンロード

アプリは、ファイルの一部(おそらく最初の14KBから100KB)のみをダウンロードします。

私は間違っていますか?

public class ApkUpdateTask extends AsyncTask <String,Void,Void>{ 
    private Context context; 
    public void setContext(Context contextf){ 
     context = contextf; 
    } 

    @Override 
    protected Void doInBackground(String... arg0) { 
     try { 
      URL url = new URL(arg0[0]); 
      HttpURLConnection c = (HttpURLConnection) url.openConnection(); 
      c.setRequestMethod("GET"); 
      c.setDoOutput(true); 
      c.connect(); 

      String PATH = "/storage/emulated/0/Download/"; 
      //String PATH = Environment.getExternalStorageDirectory().getPath(); 
      File file = new File(PATH); 
      //file.mkdirs(); 
      File outputFile = new File(file, "sonandso.apk"); 
      if(outputFile.exists()){ 
       outputFile.delete(); 
      } 
      FileOutputStream fos = new FileOutputStream(outputFile); 

      InputStream is = c.getInputStream(); 

      byte[] buffer = new byte[1024]; 
      int len1; 
      while ((len1 = is.read(buffer)) != -1) { 
       fos.write(buffer, 0, len1); 
      } 
      fos.close(); 
      is.close(); 

      Intent intent = new Intent(Intent.ACTION_VIEW); 
      //intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath())), "blahblah.apk"); 
      intent.setDataAndType(Uri.fromFile(new File("/storage/emulated/0/Download/")), "blahblah.apk"); 
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error! 
      context.startActivity(intent); 


     } catch (Exception e) { 
      Log.e("UpdateAPP", "Update error! " + e.getMessage()); 
     } 
     return null; 
    } 
} 

注:私は両方の符号付きと符号なしのAPKをした

  1. は、ここに私のコードです。どちらも完全なアプリをダウンロードできません。

  2. apkのapiレベルが、デバイスの同じapiレベルに設定されています(gradleビルドファイル内でAndroidスタジオを使用しています)。 Androidのバージョンは5.1.1です(これはプロジェクトのためです)。
  3. 私はメイン断片から上に列挙したコード(別のクラスファイルに入れたコード)を呼び出しています。これは主要なアクティビティ自体から呼び出されるべきですか?
  4. 外部のSDカードではなく内部のストレージメモリに書き込もうとしています。これが問題だろうか?もしそうなら、私はそれを内部ストレージメモリに書き込むことができますか?
  5. 私は "Environment.getExternalStorageDirectory()。getPath()"をパスに使用しようとしましたが、どちらもうまくいきませんでした。質問は#4を参照してください。

答えて

0

今のところ、私はこれを棚に置き、私がまだ研究しているGoogle APIベースのアプローチを使用することにしました。

関連する問題