0

当以下应用程序在 anoroid 上运行时,我收到消息“不幸的是它已停止”。我已经在 API 控制台中为这个包生成了客户端 ID。

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

   System.out.println("Getting Creditenal");


   Intent intent = AccountPicker.newChooseAccountIntent(null,
null, new String[]{"com.google"}, false, null, null, null, null);
   startActivityForResult(intent, CHOOSE_ACCOUNT);
       mContext = this;


  }

  @Override
  protected void onActivityResult(final int requestCode, final int
resultCode, final Intent data) {
switch (requestCode) {
case SHOW_EXCEPTION:
     if (resultCode == RESULT_OK && data != null && data.getExtras() != null) {
    AlertDialog ad1 = new AlertDialog.Builder(this).create();
        ad1.setCancelable(false); // This blocks the 'BACK' button
        mExcep += "--Sag Show Exception";
        ad1.setMessage(mExcep);
        ad1.setButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        ad1.show();
     }
case CHOOSE_ACCOUNT:
    if (resultCode == RESULT_OK) {
            String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
            credential.setSelectedAccountName(accountName);
         service = getDriveService(credential);
         SaveFileToGoogleDrive();
    }
}
}

private void SaveFileToGoogleDrive() {

     Thread t = new Thread(new Runnable() {
          @Override
          public void run() {
              File newFile = new File();
              String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
 Locale.US).format(new Date());

                newFile.setTitle(timeStamp);
            newFile.setMimeType("text/plain");
            String contentStr = "Time,Lat,Lng,Address";

              try {
                      File insertedFile = service.files().insert(
                             newFile, ByteArrayContent.fromString("text/plain",
contentStr)).execute();
                      //File insertedFile = service.files().insert(newFile).execute();
                    } catch (Exception e) {
                            mExcep = e.getMessage();
                            mExcep+=e.getLocalizedMessage();
                            startActivityForResult(credential.newChooseAccountIntent(),
SHOW_EXCEPTION)
                    }
          }
        });
        t.start();
  }

 private Drive getDriveService(GoogleAccountCredential credential) {
    return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new
    GsonFactory(), credential)
     .build();
  }

 public void showToast(final String toast) {
   runOnUiThread(new Runnable() {
    @Override
    public void run() {
      Toast.makeText(getApplicationContext(), toast,
      Toast.LENGTH_SHORT).show();
    }
  });
}

}

也没有显示异常消息框,知道 API 失败的原因吗?

4

0 回答 0