本文整理汇总了Java中com.dropbox.client2.android.AndroidAuthSession类的典型用法代码示例。如果您正苦于以下问题:Java AndroidAuthSession类的具体用法?Java AndroidAuthSession怎么用?Java AndroidAuthSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AndroidAuthSession类属于com.dropbox.client2.android包,在下文中一共展示了AndroidAuthSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLinked
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
public boolean isLinked(Activity activity) {
try {
AppKeyPair appKeys = new AppKeyPair(StaticConfig.dropboxAppKey, StaticConfig.dropboxAppSecret);
AndroidAuthSession session = new AndroidAuthSession(appKeys, AccessType.DROPBOX);
api = new DropboxAPI<AndroidAuthSession>(session);
//
KeyValueBean loginPwd = getLoginPwd(activity);
AccessTokenPair atp = new AccessTokenPair(loginPwd.getKey(),loginPwd.getValue());
api.getSession().setAccessTokenPair(atp);
// return api.getSession().isLinked();
api.metadata("/", 1, null, false, null);
return true;
}
catch (DropboxException e){
return false;
}
}
示例2: initialize
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
private void initialize(String token) {
LogUtil.log(getClass().getSimpleName(), "initialize()");
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
mDBApi = new DropboxAPI<>(session);
if ( token == null )
token = Settings.getDropboxSyncToken();
if ( token != null )
mDBApi.getSession().setOAuth2AccessToken(token);
if (!doesFolderExist(getBaseFilePath())) {
try {
createFileStructure();
} catch (DropboxException e) {
e.printStackTrace();
}
}
}
示例3: onResume
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
@Override
public void onResume() {
super.onResume();
/* Dropbox API stuff */
AndroidAuthSession session = mApi.getSession();
if (session.authenticationSuccessful()) {
try {
// Mandatory call to complete the auth
session.finishAuthentication();
// Store it locally in our app for later use
storeAuth(session);
updateUi(true);
} catch (IllegalStateException e) {
Toast.makeText(this,
"Couldn't authenticate with Dropbox:" + e.getLocalizedMessage(),
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
/* end Dropbox API stuff */
}
示例4: Login
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
/**
* Have the user login to their dropbox account.
* If the access tokens are saved from a previous
* login, they will be used, otherwise the user
* will have to login again.
*
*/
public void Login() {
if (access_type != null) {
if (!loggedIn) {
AndroidAuthSession session = buildSession();
dbApi = new DropboxAPI<AndroidAuthSession>(session);
if (container==null) {
dbApi.getSession().startAuthentication(sContainer.$formService());
} else {
dbApi.getSession().startAuthentication(container.$form());
}
}
} else {
Log.e(TAG, "AccessType is null! You MUST provide an AccessType to connect and login.");
}
}
示例5: connect
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
/**
* Handles the authentication process.
* The generated accessToken is saved, so that the user does not have to enter his/her credentials every time.
*/
@Override
public void connect() {
// Start new authentication
AndroidAuthSession mSession = new AndroidAuthSession(mAppKeys);
// The DropboxAPI Instance
mDBApi = new DropboxAPI<AndroidAuthSession>(mSession);
this.accessToken = settings.getDropboxAuthToken();
// When access token already exists in properties use it instead of starting new authentication
if (accessToken.isEmpty()) {
mDBApi.getSession().startOAuth2Authentication(activity);
} else {
mDBApi.getSession().setOAuth2AccessToken(accessToken);
}
}
示例6: disconnect
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
/**
* Unlinks the app from the users dropbox.
*/
@Override
public void disconnect() {
// Check first if application DB API link is still up!
if(mDBApi == null) {
// Start new authentication
AndroidAuthSession mSession = new AndroidAuthSession(mAppKeys);
// The DropboxAPI Instance
mDBApi = new DropboxAPI<AndroidAuthSession>(mSession);
}
mDBApi.getSession().unlink();
settings.setDropboxAuthToken("");
settings.writeChanges();
accessToken = "";
}
示例7: loadAuth
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
protected void loadAuth(AndroidAuthSession session) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(mContext);
String key = prefs.getString(ACCESS_KEY_NAME, null);
String secret = prefs.getString(ACCESS_SECRET_NAME, null);
if (key == null || secret == null || key.length() == 0
|| secret.length() == 0)
return;
if (key.equals("oauth2:")) {
// If the key is set to "oauth2:", then we can assume the token is
// for OAuth 2.
session.setOAuth2AccessToken(secret);
} else {
// Still support using old OAuth 1 tokens.
session.setAccessTokenPair(new AccessTokenPair(key, secret));
}
}
示例8: completeAuthentication
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
public void completeAuthentication() {
if (isLinked())
return;
AndroidAuthSession session = mDropboxApi.getSession();
if (session.authenticationSuccessful()) {
try {
// Mandatory call to complete the auth
session.finishAuthentication();
// Store it locally in our app for later use
storeKeys(session);
showToast(mContext.getString(R.string.text_successfully_linked_to_dropbox));
} catch (IllegalStateException e) {
showToast(mContext.getString(R.string.text_could_not_authenticate_with_dropbox)
+ e.getLocalizedMessage());
Log.i("DropboxHelper", "Error authenticating", e);
}
}
}
示例9: finishLinkRequest
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
/**
* Finishes a link request. Does nothing if {@link #mIsLinkRequested} is false prior to this call.
*
* @return true if linking is successful; false otherwise.
*/
private boolean finishLinkRequest() {
boolean isSuccessful = false;
if (mIsLinkRequested) {
synchronized (mDropboxApiLock) {
if (mDropboxApi != null) {
AndroidAuthSession session = mDropboxApi.getSession();
if (session.authenticationSuccessful()) {
try {
// Set access token on the session.
session.finishAuthentication();
isSuccessful = true;
} catch (IllegalStateException e) {
// Do nothing.
}
}
}
}
// Reset flag.
mIsLinkRequested = false;
}
return isSuccessful;
}
示例10: createPhotoFolder
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
/**
* Creates a directory for photos if one does not already exist. If the folder already exists, this call will
* do nothing.
*
* @param dropboxApi the {@link DropboxAPI}.
* @return true if the directory is created or it already exists; false otherwise.
*/
private boolean createPhotoFolder(DropboxAPI<AndroidAuthSession> dropboxApi) {
boolean folderCreated = false;
if (dropboxApi != null) {
try {
dropboxApi.createFolder(mContext.getString(R.string.wings_dropbox__photo_folder));
folderCreated = true;
} catch (DropboxException e) {
// Consider the folder created if the folder already exists.
if (e instanceof DropboxServerException) {
folderCreated = DropboxServerException._403_FORBIDDEN == ((DropboxServerException) e).error;
}
}
}
return folderCreated;
}
示例11: loadAuth
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
private void loadAuth(AndroidAuthSession session) {
SharedPreferences prefs = mContext.getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
String key = prefs.getString(ACCESS_KEY_NAME, null);
String secret = prefs.getString(ACCESS_SECRET_NAME, null);
if (key == null || secret == null || key.length() == 0 || secret.length() == 0)
{
Log.d(TAG,"No key found");
return;
}
if (key.equals("oauth2:")) {
// If the key is set to "oauth2:", then we can assume the token is for OAuth 2.
Log.d(TAG,"OAuth 2 token found");
session.setOAuth2AccessToken(secret);
} else {
// Still support using old OAuth 1 tokens.
Log.d(TAG,"OAuth 1 keypair found");
session.setAccessTokenPair(new AccessTokenPair(key, secret));
}
}
示例12: onResume
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
void onResume() {
AndroidAuthSession session = mDBApi.getSession();
if( !session.isLinked() ) {
// The next part must be inserted in the onResume() method of the
// activity from which session.startAuthentication() was called, so
// that Dropbox authentication completes properly.
if (session.authenticationSuccessful()) {
try {
Log.d(TAG, "onResume() Authentication successful");
// Mandatory call to complete the auth
session.finishAuthentication();
// Store it locally in our app for later use
storeAuth(session);
} catch (IllegalStateException e) {
Log.i(TAG, "Error authenticating", e);
}
}
}
}
示例13: onCreate
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("michael", "Dropboxclient.onCreate");
// We create a new AuthSession so that we can use the Dropbox API.
AndroidAuthSession session = buildSession();
mApi = new DropboxAPI<AndroidAuthSession>(session);
checkAppKeySetup();
if (session.getAccessTokenPair() != null) {
setLoggedIn(true);
init();
} else {
// Start the remote authentication
mApi.getSession().startAuthentication(DropboxClient.this);
// Get the metadata for a directory
setLoggedIn(mApi.getSession().isLinked());
}
}
示例14: DropboxAPISession
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
private DropboxAPISession(Context context) {
mPreference = context.getSharedPreferences(PREF_NAME,
Context.MODE_PRIVATE);
String token = mPreference.getString(KEY_ACCESS_TOKEN, null);
String secret = mPreference.getString(KEY_ACCESS_TOKEN_SECRET, null);
if (token != null && secret != null) {
AppKeyPair appKeys = new AppKeyPair(Settings.API_KEY,
Settings.API_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys,
ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
mTokens = new AccessTokenPair(token, secret);
mDBApi.getSession().setAccessTokenPair(mTokens);
}
}
示例15: buildSession
import com.dropbox.client2.android.AndroidAuthSession; //导入依赖的package包/类
private AndroidAuthSession buildSession() {
AppKeyPair appKeyPair = new AppKeyPair(DropboxApiKeys.APP_KEY, DropboxApiKeys.APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeyPair);
loadAuth(session);
return session;
}