0

我在我的 android 应用程序中使用驱动器 api 在谷歌驱动器上上传文件。我使用包名和 SHA1 密钥创建了 api 项目。但是低于错误/警告-

static final int REQUEST_AUTHORIZATION = 2;
    Context context;
    String filename;
    Drive service;
    static GoogleAccountCredential credential;
    private static final int NOTIFY_ME_ID=111991;
    private NotificationManager mgr=null;


    @Override
    public void onCreate() {  
        super.onCreate();
        credential = GoogleAccountCredential.usingOAuth2(this, Arrays.asList(DriveScopes.DRIVE_FILE));
    }

    @Override
    public void onDestroy() {        
        super.onDestroy();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {       
        context=UploadService.this;


        filename=intent.getStringExtra("file_name");
        System.out.println(" in service .. account - "+filename);
        String accountName=intent.getStringExtra("accountName");
        //service=GoogleDrive.service;

        if (accountName != null) {
            System.out.println("I am in");

            credential.setSelectedAccountName(accountName);

            service = getDriveService(credential);
            //   service = GoogleDrive.service;//getDriveService(credential);
            Uploading upload = new Uploading();
            upload.execute();
        }
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }

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



    public class Uploading extends AsyncTask<String,Void,Boolean>{
        ProgressDialog pDialog;

        boolean value1;
        @Override
        protected void onPreExecute(){
            /*   pDialog = new ProgressDialog(context);
              pDialog.setTitle("Please Wait");
              pDialog.setMessage("Uploading...");
              pDialog.setCancelable(false);
              pDialog.show();*/
            //finish();
        }
        @Override
        protected Boolean doInBackground(String... params) {

            try {
                // File's binary content //application/json; charset=UTF-8 image/jpeg
                System.out.println(" file name account - "+filename);
                java.io.File fileContent = new java.io.File(""+filename);//Environment.getExternalStorageDirectory().getAbsolutePath()+"/app.wgz");//(fileUri.getPath());
                FileContent mediaContent = new FileContent("video/mpeg", fileContent);

                // File's metadata.
                File body = new File();
                body.setTitle(fileContent.getName());
                body.setMimeType("video/mpeg");

                File file = service.files().insert(body, mediaContent).execute();
                if (file != null) {
                    //showToast("Photo uploaded: " + file.getTitle());
                    //startCameraIntent();
                    value1=true;
                }
                else
                {
                    value1=false;
                }
            } catch (UserRecoverableAuthIOException e) {
                // startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
            } catch (IOException e) {
                e.printStackTrace();
            }

            return value1;
        }
        protected void onPostExecute(Boolean params){
            super.onPostExecute(params);
            //  pDialog.dismiss();
            if(params){

                Toast.makeText(context, "File Uploaded", 10000).show();
            }
            else{
                Toast.makeText(context, "Error while uploading", 10000).show();

            }
            NotificationManager nMgr = (NotificationManager)  getSystemService(Context.NOTIFICATION_SERVICE);
            nMgr.cancel(NOTIFY_ME_ID);
            UploadService.this.stopSelf();
        }
    }

日志信息——

05-26 16:35:58.390: W/dalvikvm(8203): VFY: unable to resolve static field 4547 (auth_client_play_services_err_notification_msg) in Lcom/google/android/gms/R$string;
05-26 16:35:58.390: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x001a
05-26 16:35:58.390: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11c4 at 0x42 in Lcom/google/android/gms/auth/GoogleAuthUtil;.a
05-26 16:35:58.390: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11c5 at 0x54 in Lcom/google/android/gms/auth/GoogleAuthUtil;.a
05-26 16:35:58.400: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11c1 at 0x73 in Lcom/google/android/gms/auth/GoogleAuthUtil;.a
05-26 16:35:58.400: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11c2 at 0x76 in Lcom/google/android/gms/auth/GoogleAuthUtil;.a
05-26 16:35:58.400: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11c0 at 0x79 in Lcom/google/android/gms/auth/GoogleAuthUtil;.a
05-26 16:35:58.400: W/dalvikvm(8203): VFY: unable to resolve static field 4556 (common_google_play_services_install_title) in Lcom/google/android/gms/R$string;
05-26 16:35:58.400: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x0041
05-26 16:35:58.400: W/dalvikvm(8203): VFY: unable to resolve static field 4552 (common_google_play_services_enable_title) in Lcom/google/android/gms/R$string;
05-26 16:35:58.400: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x004c
05-26 16:35:58.400: W/dalvikvm(8203): VFY: unable to resolve static field 4562 (common_google_play_services_update_title) in Lcom/google/android/gms/R$string;
05-26 16:35:58.400: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x0057
05-26 16:35:58.400: W/dalvikvm(8203): VFY: unable to resolve static field 4559 (common_google_play_services_unsupported_title) in Lcom/google/android/gms/R$string;
05-26 16:35:58.400: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x0069
05-26 16:35:58.400: W/dalvikvm(8203): VFY: unable to resolve static field 4553 (common_google_play_services_install_button) in Lcom/google/android/gms/R$string;
05-26 16:35:58.400: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x0009
05-26 16:35:58.400: W/dalvikvm(8203): VFY: unable to resolve static field 4550 (common_google_play_services_enable_button) in Lcom/google/android/gms/R$string;
05-26 16:35:58.400: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x0010
05-26 16:35:58.400: W/dalvikvm(8203): VFY: unable to resolve static field 4560 (common_google_play_services_update_button) in Lcom/google/android/gms/R$string;
05-26 16:35:58.400: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x0017
05-26 16:35:58.410: W/dalvikvm(8203): VFY: unable to resolve static field 4557 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
05-26 16:35:58.410: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x0004
05-26 16:35:58.410: W/dalvikvm(8203): VFY: unable to resolve static field 4557 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
05-26 16:35:58.410: D/dalvikvm(8203): VFY: replacing opcode 0x60 at 0x000c
05-26 16:35:58.410: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11cb at 0x18 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b
05-26 16:35:58.410: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11ca at 0x38 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b
05-26 16:35:58.410: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11c7 at 0x3f in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b
05-26 16:35:58.410: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11d1 at 0x46 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b
05-26 16:35:58.410: I/dalvikvm(8203): DexOpt: unable to optimize static field ref 0x11ce at 0x66 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.b
05-26 16:35:58.420: E/GooglePlayServicesUtil(8203): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
05-26 16:35:58.460: W/GLSUser(1114): GoogleAccountDataService.getToken()

我该如何解决这个问题?有什么解决办法吗?

4

1 回答 1

0

未找到 Google Play 服务资源。检查您的项目配置以确保包含资源。

正如安装手册所说

要使您的应用可以使用 Google Play 服务 API,您必须引用您在安装说明的第 4 步中创建的库项目。

不仅仅是罐子。

于 2014-05-26T11:49:30.287 回答