java.lang.IllegalStateException:HTC Android 6.0 Marshmallow崩溃 - Google Play快照

时间:2017-04-06 08:11:13

标签: java android crash android-6.0-marshmallow google-play-games

我发布的应用程序适用于从Android 4.X到7.X的大多数手机。但是有一个设备,一个HTC One M9(6.0 Marshmallow),应用程序每次都会崩溃。它总是在加载主菜单并且应用程序尝试连接到谷歌播放游戏服务时发生。说实话,我没有得到错误日志。这就是我得到的:

java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:309)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
    at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.IllegalStateException: Must provide a valid file name!
    at android.os.Parcel.readException(Parcel.java:1616)
    at android.os.Parcel.readException(Parcel.java:1561)
    at com.google.android.gms.games.internal.IGamesService$Stub$Proxy.zza(Unknown Source)
    at com.google.android.gms.games.internal.GamesClientImpl.zza(Unknown Source)
    at com.google.android.gms.games.internal.api.SnapshotsImpl$2.zza(Unknown Source)
    at com.google.android.gms.games.internal.api.SnapshotsImpl$2.zza(Unknown Source)
    at com.google.android.gms.internal.zzaad$zza.zzb(Unknown Source)
    at com.google.android.gms.internal.zzaaq.zze(Unknown Source)
    at com.google.android.gms.internal.zzaaq.zzb(Unknown Source)
    at com.google.android.gms.internal.zzaav.zzb(Unknown Source)
    at com.google.android.gms.internal.zzaat.zzb(Unknown Source)
    at com.google.android.gms.games.internal.api.SnapshotsImpl.open(Unknown Source)
    at com.google.android.gms.games.internal.api.SnapshotsImpl.open(Unknown Source)
    at com.duke.privatpc.quiztest.MainActivity$2.doInBackground(MainActivity.java:362)
    at com.duke.privatpc.quiztest.MainActivity$2.doInBackground(MainActivity.java:357)
    at android.os.AsyncTask$2.call(AsyncTask.java:295)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    ... 4 more

此外,日志中的两行引用了我在这些方法中的MainActivity.java(此处为“Snapshots.OpenSnapshotResult open”):

private void savedGamesUpdate() {
        final String snapshotName = makeSnapshotName(APP_STATE_KEY);
        final boolean createIfMissing = true;

        // Use the data from the EditText as the new Snapshot data.
        final byte[] data = mSaveGameData;

        AsyncTask<Void, Void, Boolean> updateTask = new AsyncTask<Void, Void, Boolean>() {


            @Override
            protected Boolean doInBackground(Void... params) {
                Snapshots.OpenSnapshotResult open = Games.Snapshots.open(
                        mGoogleApiClient, snapshotName, createIfMissing).await();

                if (!open.getStatus().isSuccess()) {
                    return false;
                }

                Bitmap coverImage = BitmapFactory.decodeResource(MainActivity.this.getResources(),
                        R.mipmap.autosave);
                String desc = "Autosave "+android.os.Build.MODEL;
                // Create the change operation
                SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
                        .setCoverImage(coverImage)
                        .setDescription(desc)
                        .build();

                // Change data but leave existing metadata
                Snapshot snapshot = open.getSnapshot();
                snapshot.getSnapshotContents().writeBytes(data);

                Snapshots.CommitSnapshotResult commit = Games.Snapshots.commitAndClose(
                        mGoogleApiClient, snapshot, metadataChange).await();

                if (!commit.getStatus().isSuccess()) {
                    return false;
                }

                // No failures
                return true;
            }

            @Override
            protected void onPostExecute(Boolean result) {
                dismissProgressDialog();

            }
        };
        updateTask.execute();
    }

和这一个:

   private String makeSnapshotName(int appStateKey) {
        if(isAnHTCDevice()){
            return "Autosave HTC";
        }else{
            if(android.os.Build.MODEL != null){
                return "Autosave"+android.os.Build.MODEL;
            }else{
                return "Autosave";
            }
        }

    }

    public boolean isAnHTCDevice()
    {
        String manufacturer = android.os.Build.MANUFACTURER;
        if (manufacturer.toLowerCase().contains("htc"))
            return true;
        else
            return false;
    }

任何人都知道原因可能是什么?

1 个答案:

答案 0 :(得分:0)

RTFM。正如文档中所述,[Snapshots.open](https://developers.google.com/android/reference/com/google/android/gms/games/snapshot/Snapshots.html#open(com.google.android.gms.common.api.GoogleApiClient,java.lang.String,boolean))

  

要打开的快照文件的名称。必须介于1到100个非URL保留字符(a-z,A-Z,0-9或符号“ - ”,“。”,“_”或“〜”)之间。

所以,修改makeSnapshotName方法以生成有效的文件名。