3

アプリに拡張ファイルをダウンロードさせようとしています。これが私のメインです:

package tm.down.rob;

import com.google.android.vending.expansion.downloader.DownloadProgressInfo;
import com.google.android.vending.expansion.downloader.DownloaderClientMarshaller;
import com.google.android.vending.expansion.downloader.Helpers;
import com.google.android.vending.expansion.downloader.IDownloaderClient;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Messenger;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.TextView;

public class main extends Activity implements IDownloaderClient {
    /** Called when the activity is first created. */

    TextView tv1;

    @Override
     public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      //////////
      tv1 = (TextView)findViewById(R.id.textView1);
      //////////

      // Check whether the file have been downloaded.
      String mainFileName = Helpers.getExpansionAPKFileName(this, true, 1);
      boolean fileExists = Helpers.doesFileExist(this, mainFileName, 32921796L, false);

      if (!fileExists) {
       Intent launcher = getIntent();
       Intent fromNotification = new Intent(this, getClass());
       fromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
       fromNotification.setAction(launcher.getAction());

       if (launcher.getCategories() != null) {
        for (String cat : launcher.getCategories()) {
         fromNotification.addCategory(cat);
        }
       }

       PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, fromNotification, PendingIntent.FLAG_UPDATE_CURRENT);

       try {

        int result = DownloaderClientMarshaller.startDownloadServiceIfRequired( this, pendingIntent, ExpansionFileDownloaderService.class);
        if (DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED != result) {

            // implement Downloading UI.
            tv1.setText("Need to download.");

         return;
        }

       } catch (Exception e) { 
        Log.e("apk-expansion-files", "NameNotFoundException occurred. " + e.getMessage(), e);
       }
      }

      tv1.setText("Downloaded!");

     }


    ///////////////////////////////////////////////////


    @Override
    public void onServiceConnected(Messenger m) {
        tv1.setText("onServiceConnected: " + m.toString() );
    }

    ///////////

    @Override
    public void onDownloadStateChanged(int newState) {
        tv1.setText("onDownloadStateChanged: " + String.valueOf(newState) );
    }

    ////////////

    @Override
    public void onDownloadProgress(DownloadProgressInfo progress) {
        ProgressBar mPB = (ProgressBar)findViewById(R.id.progressBar1);

        progress.mOverallTotal = progress.mOverallTotal;
        mPB.setMax((int) (progress.mOverallTotal >> 8));
        mPB.setProgress((int) (progress.mOverallProgress >> 8));
        //mProgressPercent.setText(Long.toString(progress.mOverallProgress * 100 / progress.mOverallTotal) + "%");
        //mProgressFraction.setText(Helpers.getDownloadProgressString(progress.mOverallProgress,progress.mOverallTotal));

    }

    ////////////




}

apk をコンパイルし、zip ファイルの名前をmain.1.tm.down.rob.obbに変更してマーカーにアップロードしましたが、アプリを実行すると、「リソースが見つからなかったため、ダウンロードに失敗しました」というメッセージが表示されます。 ...

何か案は?ありがとう!

4

1 に答える 1