Android 台灣中文網

標題: dropbox get list of file intent [打印本頁]

作者: soul810707    時間: 2013-7-19 16:46
標題: dropbox get list of file intent
我在dropbox 官方的sdk範例上   利用intent    來做出一個檔案清單


加上 (****那是我加的intent)


public void onClick(View v) {
                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);
             *****  Intent intent = new Intent();
                    intent.setClass(Main.this, list.class);
                    startActivity(intent);
                    Main.this.finish();********   
            }
但當我按下連結後 就會當掉   無法進入到連結網頁驗證的的部分   也無法到另一個xml檔


  請問我intent 的地方是否錯了嗎???
作者: ploglin    時間: 2013-7-22 11:37
你有設定允許Intenet的權限嗎?
作者: soul810707    時間: 2013-7-22 15:49
有ㄟ   想說利用官網給的SDK    做一個dropbox的檔案清單   

知道需要用到  Entry entries = mApi.metadata(Path, 100, null, true, null);  

但想先利用intent   登入完後  到list intent 但就失敗了   
作者: ploglin    時間: 2013-7-22 17:08
那你把 Locat 中的 Error 放上來讓大家幫你看看,這樣比較快
作者: soul810707    時間: 2013-7-22 21:39
謝謝回復:)
因為logcat 的錯誤太多了    我貼不完  以下是dropbox 官網提供的api example 他有提供三個檔案 一個上傳 一個下載 一個主認證  認證的地方在下面
我試過很多地方  以下有笑臉的地方是我試過  但都無法成功的跳的另一個intent   不知道我
  Intent intent = new Intent();
                intent.setClass(DBRoulette.this, list.class);
                startActivity(intent);
                DBRoulette.this.finish();   該擺在哪阿~~  
然後有個小疑問  為何不能在紅字那邊 改成 list.class   直接跳過去?
[code]
public class DBRoulette extends Activity {
    private static final String TAG = "DBRoulette";
  final static private String APP_KEY = "bsobztcrcac2a36";
    final static private String APP_SECRET = "njp7yxg8f1aypci";

    // If you'd like to change the access type to the full Dropbox instead of
    // an app folder, change this value.
    final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER;


    // You don't need to change these, leave them alone.
    final static private String ACCOUNT_PREFS_NAME = "prefs";
    final static private String ACCESS_KEY_NAME = "ACCESS_KEY";
    final static private String ACCESS_SECRET_NAME = "ACCESS_SECRET";


    DropboxAPI<AndroidAuthSession> mApi;

    private boolean mLoggedIn;

    // Android widgets
    private Button mSubmit;
    private LinearLayout mDisplay;
    private Button mPhoto;
    private Button mRoulette;

    private ImageView mImage;

    private final String PHOTO_DIR = "/Photos/";

    final static private int NEW_PICTURE = 1;
    private String mCameraFileName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (savedInstanceState != null) {
            mCameraFileName = savedInstanceState.getString("mCameraFileName");
        }

        // We create a new AuthSession so that we can use the Dropbox API.
        AndroidAuthSession session = buildSession();
        mApi = new DropboxAPI<AndroidAuthSession>(session);

        // Basic Android widgets
        setContentView(R.layout.main);

        checkAppKeySetup();

        mSubmit = (Button)findViewById(R.id.auth_button);

        mSubmit.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // This logs you out if you're logged in, or vice versa
                if (mLoggedIn) {
                    logOut();
                } else {
                    // Start the remote authentication
                    mApi.getSession().startAuthentication(DBRoulette.this);
                  
                    
                    
                }
            }
            
           
           
        });

      //  mDisplay = (LinearLayout)findViewById(R.id.logged_in_display);
          // Display the proper UI state if logged in or not
        setLoggedIn(mApi.getSession().isLinked());
  

   

    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putString("mCameraFileName", mCameraFileName);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        AndroidAuthSession session = mApi.getSession();

        // 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 {
                // Mandatory call to complete the auth
                session.finishAuthentication();

                // Store it locally in our app for later use
                TokenPair tokens = session.getAccessTokenPair();
                storeKeys(tokens.key, tokens.secret);
                setLoggedIn(true);
              
            } catch (IllegalStateException e) {
                showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
                Log.i(TAG, "Error authenticating", e);
            }
        }
      
    }

    // This is what gets called on finishing a media piece to import
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == NEW_PICTURE) {
            // return from file upload
            if (resultCode == Activity.RESULT_OK) {
                Uri uri = null;
                if (data != null) {
                    uri = data.getData();
                }
                if (uri == null && mCameraFileName != null) {
                    uri = Uri.fromFile(new File(mCameraFileName));
                }
                File file = new File(mCameraFileName);

                if (uri != null) {
                    UploadPicture upload = new UploadPicture(this, mApi, PHOTO_DIR, file);
                    upload.execute();
                }
            } else {
                Log.w(TAG, "Unknown Activity Result from mediaImport: "
                        + resultCode);
            }
        }
    }

    private void logOut() {
        // Remove credentials from the session
        mApi.getSession().unlink();

        // Clear our stored keys
        clearKeys();
        // Change UI state to display logged out version
        setLoggedIn(false);
    }

    /**
     * Convenience function to change UI state based on being logged in
  private void setLoggedIn(boolean loggedIn) {
            mLoggedIn = loggedIn;
            if (loggedIn) {
                   
        mSubmit.setText("Unlink from Dropbox");
            mDisplay.setVisibility(View.VISIBLE);
     

            } /*else {
                    mSubmit.setText("Link with Dropbox");
            mDisplay.setVisibility(View.GONE);
            mImage.setImageDrawable(null);
            }*/
    }
   




歡迎光臨 Android 台灣中文網 (https://apk.tw/) Powered by Discuz! X3.1