How to declare a FragmentActivity in an IntentService?

0

My current problem is that I need to use the Google Drive API in an IntentService, but my problem is that one of its fundamental classes or methods for its use can not be implemented, because it has a FragmentActivity value. And I can not think of a clear way to declare it in a service.

The code that gives me error:

private GoogleApiClient apiClient;
apiClient = new GoogleApiClient.Builder(this)
        .enableAutoManage(this,0, this)
        .addApi(Drive.API)
        .addScope(Drive.SCOPE_FILE)
        .addScope(Drive.SCOPE_APPFOLDER)
        .build();

In case what gives me the problem is this part:

.enableAutoManage("Aquí me pide el FragmentActivity",0, this)

My goal is to be able to read a file that is in Google Drive with the following code, but I get an error because the GoogleApiClient is not declared well.

My service code code:

public class Ser extends IntentService implements ConnectionCallbacks, OnConnectionFailedListener{
private Context mContext;
private Handler mHandler;
private GoogleApiClient apiClient;
public Ser(String name) {
    super("hola");
    mHandler = new Handler();
    // TODO Auto-generated constructor stub
}

private boolean readFile(DriveId fileDriveId) {

    DriveFile file = fileDriveId.asDriveFile();

    file.open(apiClient, DriveFile.MODE_READ_ONLY, null)
        .setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
            @Override
            public void onResult(DriveApi.DriveContentsResult result) {
                if (!result.getStatus().isSuccess()) {
                    Log.e("LOGTAG","Error al abrir fichero (readFile)");
                    return;
                }

                DriveContents contents = result.getDriveContents();

                Toast.makeText(Ser.this, "si", Toast.LENGTH_LONG).show();


                contents.discard(apiClient);

            }
       });


    return true;
}

@Override
protected void onHandleIntent(Intent arg0) {
    // TODO Auto-generated method stub
mContext = getApplicationContext();


    mHandler.post(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
        apiClient = new GoogleApiClient.Builder(this)

         .addApi(Drive.API)
         .addScope(Drive.SCOPE_FILE)
         .addScope(Drive.SCOPE_APPFOLDER)
         .build();


            readFile(DriveId.decodeFromString("DriveId:CAESABiQBCCWrt-IBIYoAA=="));

        }

    });
}

@Override
public void onConnected(Bundle arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onConnectionSuspended(int arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onConnectionFailed(ConnectionResult result) {
    // TODO Auto-generated method stub

}

}

is not declared well because I do not add: .enableAutoManage(this,0, this) , because you need a FragmentActivity or an Activity as a value

If you know a way to solve this problem. I will be happy to hear your comments and answers. Thanks

    
asked by Abraham.P 28.04.2017 в 00:18
source

0 answers