2

我正在尝试使用 Alljoyn 框架传输文件,Alljoyn 提供的示例向我展示了如何发送和接收通过单击 fileExplorer 的 ListView 选择的一个文件。 问题是我想传输几个选定的文件,例如 4 张图片,一次

在 onActivityResult() case OFFER_SELECTED_FILE:i 修改如下:

case OFFER_SELECTED_FILE: {

    final String[] peers = ajManager.getPeers();
    //create the click listener - when a peer is selected, offer them the file
    DialogInterface.OnClickListener onPeerClicked = new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {

            String peer = peers[which];
            //File file = (File) intent.getExtras().get("file"); 
            File selected = (File) intent.getExtras().get("file"); 

            ArrayList<String> filePath = new ArrayList<String>();
            filePath.add(selected.getAbsolutePath());
            //ftComponent.offerFileToPeer(peer, file.getAbsolutePath(), 1000);                      
            ftComponent.offerFileToPeer(peer, filePath, 1000);                      
        }
    };
    showPeerPickerDialog(onPeerClicked);
    break;
}

但它被无法修改的公共类 FileTransferComponent 拒绝。

public int offerFileToPeer(String peer, String filePath, int timeoutMSecs) {

    return offerManager.offerFile(peer, filePath, timeoutMSecs);
}

我参考了Android*4.1.1基本文件传输程序的*文件传输模块使用指南如下:

发送方

ftComponent.announce(filePaths);

接收端

ArrayList<FileDescriptor> availableFiles = ftComponent.getAvailableRemoteFiles();
FileDescriptor selected = availableFiles.get(0);
ftComponent.requestFile(selected.owner, selected.fileId, selected.filename);

帮助,任何建议都将不胜感激。我是 alljoyn 的新手。如果可能的话,请告诉我如何做 Receicer&&Sender 的双方。thx

4

1 回答 1

2

well,i got the solution days ago, as follows:

 //ready the selected the files's path list
  File selected = (File) intent.getExtras().get("file");
  filePaths = new ArrayList<String>();
  filePaths.add(selected.getAbsolutePath());    
 //in the offer event
 private FileTransferComponent ftComponent;
  for (String path : filePaths) {
      ftComponent.offerFileToPeer(peer, path, 1000);//the sample's original statement
      }

the Alljoyn sample shows me transfer one file,thus we just need to use something like for(a:a_list){...} to do with it.and the Alljoyn will handle the rest.

ps.i have got a headache with people who just talk big but no suggested output.if u are too proud to answer some question,please do not waste time here.Thx.

于 2014-11-26T07:14:08.280 回答