Dropbox的确认对话框弹出每隔时候,按钮被点击 [英] Dropbox confirmation dialog pop-up every times when button is clicked

查看:316
本文介绍了Dropbox的确认对话框弹出每隔时候,按钮被点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的app.When实施的Dropbox我点击一个按钮,我连接到​​Dropbox的。

I am implementing dropbox in my app.When I am clicking a button I am connecting to dropbox.

问题

每一个当我点击按钮,Dropbox的确认对话框弹出,我想避免这种成功auithentication和一次性确认后。

Each and every time when I click the button,the dropbox confirmation dialog pops up and I want to avoid that after successful auithentication and one time confirmation.

的code

       public static boolean mLoggedIn = false; 
        private boolean isItemClicked = false;
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.dropboxdownload);
                lvDropboxDownloadFilesList = (ListView)                                            findViewById(R.id.lvDropboxDownloadFilesList);


                AndroidAuthSession session = buildSession();
                mApi = new DropboxAPI<AndroidAuthSession>(session);



                if (!Constants.mLoggedIn)
                    mApi.getSession().startAuthentication(DropboxDownload.this);

                lvDropboxDownloadFilesList.setOnItemClickListener(this);
            }

        private AndroidAuthSession buildSession() {
                AppKeyPair appKeyPair = new AppKeyPair(Constants.DROPBOX_APP_KEY,
                        Constants.DROPBOX_APP_SECRET);
                AndroidAuthSession session;

                String[] stored = getKeys();
                if (stored != null) {
                    AccessTokenPair accessToken = new AccessTokenPair(stored[0],
                            stored[1]);
                    session = new AndroidAuthSession(appKeyPair, Constants.ACCESS_TYPE,
                            accessToken);
                } else {
                    session = new AndroidAuthSession(appKeyPair, Constants.ACCESS_TYPE);
                }

                return session;
            }


        private AndroidAuthSession buildSession() {
                AppKeyPair appKeyPair = new AppKeyPair(Constants.DROPBOX_APP_KEY,
                        Constants.DROPBOX_APP_SECRET);
                AndroidAuthSession session;

                String[] stored = getKeys();
                if (stored != null) {
                    AccessTokenPair accessToken = new AccessTokenPair(stored[0],
                            stored[1]);
                    session = new AndroidAuthSession(appKeyPair, Constants.ACCESS_TYPE,
                            accessToken);
                } else {
                    session = new AndroidAuthSession(appKeyPair, Constants.ACCESS_TYPE);
                }

                return session;
            }


            private String[] getKeys() {
                SharedPreferences prefs = getSharedPreferences(
                        Constants.ACCOUNT_PREFS_NAME, 0);
                String key = prefs.getString(Constants.ACCESS_KEY_NAME, null);
                String secret = prefs.getString(Constants.ACCESS_SECRET_NAME, null);
                if (key != null && secret != null) {
                    String[] ret = new String[2];
                    ret[0] = key;
                    ret[1] = secret;
                    return ret;
                } else {
                    return null;
                }
            }


@Override
    protected void onResume() {

        super.onResume();
        AndroidAuthSession session = mApi.getSession();

        if (session.authenticationSuccessful()) {
            try {
                session.finishAuthentication();

                TokenPair tokens = session.getAccessTokenPair();
                storeKeys(tokens.key, tokens.secret);
                setLoggedIn(true);
            } catch (IllegalStateException e) {
                showToast("Couldn't authenticate with Dropbox:"
                        + e.getLocalizedMessage());
            }
        }
    }


    public void setLoggedIn(final boolean loggedIn) {
        pd = ProgressDialog.show(DropboxDownload.this, null,
                "Retrieving data...");
        new Thread(new Runnable() {

            @Override
            public void run() {
                Constants.mLoggedIn = loggedIn;
                if (loggedIn) {
                    int i = 0;
                    com.dropbox.client2.DropboxAPI.Entry dirent;
                    try {
                        dirent = mApi.metadata(DIR, 1000, null, true, null);
                        files = new ArrayList<com.dropbox.client2.DropboxAPI.Entry>();
                        dir = new ArrayList<String>();
                        for (com.dropbox.client2.DropboxAPI.Entry ent : dirent.contents) {
                            files.add(ent);
                            dir.add(new String(files.get(i++).path));
                        }
                        i = 0;
                        mHandler.sendEmptyMessage(0);
                    } catch (DropboxException e) {
                        e.printStackTrace();
                    }

                }
            }
        }).start();

我咨询堆栈溢出,并发现我每次它为空或没有时间检查访问秘密访问键,我已经检查了(见buildSession()),但仍然问题是persisting.What我错了在做??帮助please.I正在使用的核心API。

I consulted stack overflow and find that I have to check the access secret and access key each time that it is null or not and I have checked that(see buildSession()).But still the problem is persisting.What wrong I am doing??Help please.I am using core api.

推荐答案

如何手动设置访问用户访问令牌对。

How to set access user access token pair manually.

 AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
 AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
 if (mDBApi == null) {
    mDBApi = new DropboxAPI<AndroidAuthSession>(session);

//  mDBApi.getSession().startAuthentication(Main.this);  //kicks off the web-based authentication
      //you'll have to use the web-based authentication UI one-time to get the ######### values
        String token_key="#########";  
        String token_seceret="#########";
        AccessTokenPair tokens=new AccessTokenPair(token_key,token_seceret);
        mDBApi.getSession().setAccessTokenPair(tokens);     
  //  boolean v=mDBApi.getSession().authenticationSuccessful(); 
    }

我第一次在调试模式破发点的应用,我得到的保存在detail.and输入有效的日志令牌密钥和令牌密钥(注)的证书之后,我手动设置如上code然后就可以成功登录。

First time i run application in debug mode with break point i get the token key and token secret of by entering valid log in detail.and saved(noted) that credential and after that i set them manually as above code then can be log in successfully.

和也看看Dropbox的示例应用程序DBRoulette。

And also have a look at Dropbox example app DBRoulette.

从这里 信息

info from here

这篇关于Dropbox的确认对话框弹出每隔时候,按钮被点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆