android


openFileActivityBuilder intent. How to wait for it to connect and how to get the file out of it


I'm using Google Drive API for android. This is the code I have right now.
public void downloadFromDrive(){
mGoogleApiClient.connect();
IntentSender intentSender = Drive.DriveApi.newOpenFileActivityBuilder().setMimeType(new String[]{"text/plain"}).build(mGoogleApiClient);
try{
startIntentSenderForResult(intentSender,2,null,0,0,0);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
Log.w(TAG, "Unable to send intent", e);
}
}
Currently there are 2 problems with it. Since there is no resultcallback mGoogleClient doesn't connect with mGoogleApiClient.connect(). Any ideas on how to wait until it actually is connected? Using isConnected() or onConnect() only puts me in a infinite loop. I just currently connect the API client in a different method first(the one that uploads stuff)
How do I get a FileStream out of the IntentSender? I have code on how to upload to Google Drive, and I never had to specify my OutputStreamWriter in any method. I just created an Output stream, called the intentsender and the GUI uploaded the file no problem.
The first part of the problem has been solved by the lovely people in the comments above. (enableAutoManage)
Getting a file stream out of the IntentSender can be achieved by editing the OnActivityResult method.
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
System.out.println("ONACTIVITY RESULT");
System.out.println("REQUEST CODE" + requestCode);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
System.out.println("GOOGLE SIGN IN");
}
if(requestCode == 2){
try{
mDriveID = data.getParcelableExtra(OpenFileActivityBuilder.EXTRA_RESPONSE_DRIVE_ID);
System.out.println("ONACTIVITY DRIVE ID " + mDriveID);
}
catch (NullPointerException e) {
}
}
}
onActivityResults executes every time you are finished with a GoogleDrive intent(I think, not sure). So you have to catch an error in case you start an IntentSender for anything else. This isnt the most concise answer, but it worked.

Related Links

How to create a code that download a video from Server as done in YouTube app
Could not able to find shared preference file in android studio(7.0 version nougat)?
how to run a job service at a given time
Displaying images from URL in Listview with picasso
How my Scrollrect in UNITY 3d become Responsive for all screen size for android mobile phones only
SDK's fragment interaction
constraint layout inside scrollview white space at bottom?
Error: Error validating package name. Package name must look like: com.company.Name
React Native Gifted Chat chat box is going out of view
Vuforia- Merge User defined targets with VideoPlayback
How do I send notification at random time?
Send Email Via Android
runing an android mobile application on android emulator
Script that will make a backup pictures and movies from android smartphone to connected USB flash drive
Why are my dynamically added ListViews to a LinearLayout not displaying properly?
how to receive intent from headset button

Categories

HOME
shell
dns
twig
mysql-workbench
serialization
solaris
jsf-2.2
simulink
retrofit2
heap
siddhi
java.util.logging
activecollab
redis-sentinel
code-generation
shared-libraries
package.json
identity-management
cfml
sigma.js
apache2.4
articulate-storyline
ms-access-web-app
outliers
nstimer
soot
paperjs
cppreference
failover
mql
postback
r-grid
android-sugarorm
dsx-desktop
browser-extension
playframework-2.1
git-rewrite-history
flatmap
parser-generator
android-ibeacon
glm-math
smoothstate.js
signal-strength
clang++
monkey-testing
dotnet-httpclient
singleinstance
spring-data-couchbase
java-6
backbone-collections
git-flow
juice-ui
reachability
usart
pure-css
macaulay2
jquery-jscrollpane
vorpal.js
aurora
design-principles
libvlc
grgit
xenomai
zen-cart
opserver
evolus-pencil
mod-proxy
nutiteq
umlgraph
grouping-sets
delayed-execution
cancellation
matrix-inverse
malformedurlexception
xml-dsig
koala
isqlquery
modular
abstract-data-type
cascadingdropdown
pyunit
google-maps-mobile
google-floodlight
timthumb
cuteeditor
appledoc
luajava
resharper-6.0
vs-android
zend-rest
google-wave
fdf
dsoframer
movieplayer
blind

Resources

Encrypt Message