I am creating an android application which should have access to a google drive account in order to store and read files in/from google drive. I used google drive android API for this purpose. but the problem is that when the user signs in to the account through the application, the account is also added to the device and the account is accessible through drive, gmail,... applications and I need to restrict the access to that google account to only my application.
Is there anyway to restrict access to google account to just my application?
I show some code related to connecting to google drive below:
public class MainActivity extends Activity implements ConnectionCallbacks, OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
// Request code to use when launching the resolution activity
private static final int REQUEST_RESOLVE_ERROR = 1001;
private boolean mResolvingError = false;
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//start connection to google play
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub
if (mResolvingError) {
// Already attempting to resolve an error.
return;
} else if (result.hasResolution()) {
try {
mResolvingError = true;
result.startResolutionForResult(this,REQUEST_RESOLVE_ERROR);
} catch (SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
showErrorDialog(result.getErrorCode());
mResolvingError = true;
}
}
@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
showMessage("Connected to account");
}
protected void onPause()
{
showMessage("onPause");
super.onPause();
}
protected void onStart() {
super.onStart();
showMessage("onStart");
if (!mResolvingError && !mGoogleApiClient.isConnected()) { // more about this later
mGoogleApiClient.connect();
}
}
@Override
protected void onStop() {
showMessage("OnStop");
//mGoogleApiClient.disconnect();
super.onStop();
}
protected void onRestart()
{
showMessage("onRestart");
super.onRestart();
if (!mResolvingError && !mGoogleApiClient.isConnected()) { // more about this later
mGoogleApiClient.connect();
}
}
public void showMessage(String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
}
In fact I am making an application which we use to collect data from our users, and therefore we want the data to be stored in a central storage space which both we and other users of application can have access to data.(users have limited access to data through our application). we did the same with dropbox and it works well. but due to some restrictions on accessing dropbox by users, I am looking for alternative solutions. for now I am trying to do the same with google drive. does anyone have any solution about how should I do this??
in fact the google account has nothing to do with the users of application, it's my google account in which the data coming from application should be stored.