使用smack api的文件传输问题

时间:2011-07-01 04:52:48

标签: java android

我正在使用smack api和开火xmmp服务器进行文件传输,  我做了发送文件的代码

try {
        servicemanager = new ServiceDiscoveryManager(connection);
        manager = new FileTransferManager(connection);
        FileTransferNegotiator.setServiceEnabled(connection, true);
        OutgoingFileTransfer transfer = manager
                .createOutgoingFileTransfer(receid);
        System.out.println(connection);
        transfer.sendFile(new File(comppath), "hi");
        while (!transfer.isDone()) {

            Toast.makeText(this,
                    "status." + transfer.getStatus().toString(),
                    Toast.LENGTH_LONG).show();

            // System.out.println(transfer.getStreamID() + " is done!");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                Toast.makeText(this, "corrupted..", Toast.LENGTH_LONG)
                        .show();
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

并且在public void onCreate(Bundle icicle)我为文件传输做了lisener

super.onCreate(icicle);
servicemanager = new ServiceDiscoveryManager(connection);
    FileTransferNegotiator.setServiceEnabled(connection, true);

    manager = new FileTransferManager(connection);

    manager.addFileTransferListener(new FileTransferListener() {
        public void fileTransferRequest(FileTransferRequest request) {
            Log.d("", "allows file...");
            if (request != null) {
                // Accept it
                IncomingFileTransfer transfer = request.accept();
                try {

                    /*String pathsd = Environment
                            .getExternalStorageDirectory().toString();*/

                    String path = "/sdcard/"+ request.getFileName();
                    transfer.recieveFile(new File(path));

                    // transfer.recieveFile(new
                    // File(request.getFileName()));
                    // System.out.println("File " +
                    // request.getFileName() + "Received Successfully");
                    Log.d("", "rece: " + request.getFileName());
                    Log.d("", "path: " + request.getFileName());
                    // InputStream input = transfer.recieveFile();
                } catch (XMPPException ex) {
                    Log.d("", "er: " + ex);
                }
            } else {
                Log.d("", "reject file...");
                request.reject();
            }
        }
    });

这里的lisener没有回应任何事情..另一方......

wat是我的错...

提前感谢。

0 个答案:

没有答案