2016-08-14 40 views
0

試圖從kinvey公開訪問的文件下載到Android應用 嘗試以下代碼下載文件,如何從kinvey在android系統

FileOutputStream fos = new FileOutputStream(videoName); 
     FileMetaData meta = new FileMetaData(videoName); 
     meta.setId(videoName); 
     kinveyClient.file().downloadWithTTL(meta.getId(), 1200000, fos, new DownloaderProgressListener() { 
      @Override 
      public void progressChanged(MediaHttpDownloader downloader) throws IOException { 
       Log.i("", "progress updated: " + downloader.getDownloadState()); 
       final String state = new String(downloader.getDownloadState().toString()); 

       getActivity().runOnUiThread(new Runnable() { 
        @Override 
        public void run() { 
         //tProgress.setText((tProgress.getText() == null) ? state : tProgress.getText() + "\n" + state) 
        } 
       }); 
      } 

      @Override 
      public void onSuccess(Void result) { 
      } 

      @Override 
      public void onFailure(Throwable error) { 
      } 
     }); 

獲取事件的成功,但是數據沒有被接收。任何想法這將如何工作?

這樣得到錯誤:

failure com.kinvey.java.core.KinveyJsonResponseException: InsufficientCredentials 
                  The credentials used to authenticate this request are not authorized to run this operation. Please retry your request with appropriate credentials 
+0

顯然,'progressChanged'方法被調用的MainThread已經,爲什麼你使用' runOnUiThread'? – Bhargav

回答

0

根據文檔,這是你應該如何使用你從getDownloadState()獲得的價值。爲了獲得你的下載進度,你需要首先檢查下載狀態等於DOWNLOAD_IN_PROGRESS的值,然後用download.getProgress()方法獲得進度,然後你可以用它來更新進度滑塊上的值,(你不應使用toString()方法就像你之前所做的那樣可以將這些值的字符串。從documentation here

0

Nayana採取

public void progressChanged(MediaHttpDownloader downloader) throws IOException { 
    switch (downloader.getDownloadState()) { 
    case DOWNLOAD_IN_PROGRESS: 
     //Download in progress 
     //Download percentage: + downloader.getProgress() 
     break; 
    case DOWNLOAD_COMPLETE: 
     //Download Completed! 
     break; 
    } 
} 

代碼,

因爲用戶做你可能會得到這個錯誤沒有訪問權限文件中。您可以試着解決您的問題:

  • 如果您使文件公開可讀,所有經過身份驗證的用戶將能夠訪問該特定文件。
  • 您可以通過在ACL中添加 少數用戶的讀/寫權限來訪問該文件。

此外,檢查訪問控制列表的文檔: http://devcenter.kinvey.com/rest/guides/security#entityanduserpermissions

感謝, Pranav Kinvey支持