私はAndroidプログラミングの初心者です。ファイル転送機能を備えたメッセンジャーアプリケーションを開発しようとしています。しかし、ファイル転送に関して問題があります。
viewer.java**
Button transfer = (Button) findViewById(R.id.btnimage);
transfer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
XMPPClient.getInstance().SendFile(to, selectedImagePath);
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
そして、私はXMPPCLIENT.Javaを持っています
public void ReceiveFile() {
Thread thread = new Thread() {
public void run() {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager
.getInstanceFor(getConnection());
if (sdm == null)
sdm = new ServiceDiscoveryManager(getConnection());
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
// Create the file transfer manager
final FileTransferManager managerListner = new FileTransferManager(
getConnection());
FileTransferNegotiator.setServiceEnabled(getConnection(), true);
Log.i("File transfere manager", "created");
// Create the listener
managerListner
.addFileTransferListener(new FileTransferListener() {
public void fileTransferRequest(
final FileTransferRequest request) {
Log.i("Recieve File",
"new file transfere request new file transfere request new file transfere request");
Log.i("file request",
"from" + request.getRequestor());
IncomingFileTransfer transfer = request
.accept();
Log.i("Recieve File alert dialog", "accepted");
try {
transfer.recieveFile(new File("/sdcard/"
+ request.getFileName()));
while (!transfer.isDone()
|| (transfer.getProgress() < 1)) {
Thread.sleep(1000);
Log.i("Recieve File alert dialog",
"still receiving : "
+ (transfer
.getProgress())
+ " status "
+ transfer.getStatus());
if (transfer.getStatus().equals(
Status.error)) {
// Log.i("Error file",
// transfer.getError().getMessage());
Log.i("Recieve File alert dialog",
"cancelling still receiving : "
+ (transfer
.getProgress())
+ " status "
+ transfer
.getStatus());
transfer.cancel();
break;
}
}
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
};
thread.start();
}
public void SendFile(final String Receiver, final String Directory) {
Thread thread = new Thread() {
public void run() {
ServiceDiscoveryManager sdm = ServiceDiscoveryManager
.getInstanceFor(getConnection());
if (sdm == null)
sdm = new ServiceDiscoveryManager(getConnection());
sdm.addFeature("http://jabber.org/protocol/disco#info");
sdm.addFeature("jabber:iq:privacy");
// Create the file transfer manager
FileTransferManager manager = new FileTransferManager(
mConnection);
FileTransferNegotiator
.setServiceEnabled(getConnection(), true);
// Create the outgoing file transfer
OutgoingFileTransfer transfer = manager
.createOutgoingFileTransfer(getJIDofUserID(Receiver));
sendMessage(getJIDofUserID(Receiver), "image");
Log.i("transfere file", "outgoingfiletransfere is created");
try {
OutgoingFileTransfer.setResponseTimeout(30000);
transfer.sendFile(new File(Directory), "Description");
Log.i("transfere file", "sending file");
while (!transfer.isDone()) {
try {
Thread.sleep(1000);
Log.i("transfere file", "sending file status "
+ transfer.getStatus() + "progress: "
+ transfer.getProgress());
if (transfer.getStatus() == org.jivesoftware.smackx.filetransfer.FileTransfer.Status.error) {
transfer.cancel();
Log.e("",transfer.getError()+" error");
break;
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
Log.e("aaaaaaaaaaaaaaa","aaaa"+e);
e.printStackTrace();
}
}
}
catch (XMPPException e) {
// TODO Auto-generated catch block
Log.e("aaaaaaaaaaaaaaa","aaaa"+e);
e.printStackTrace();
}
Log.i("transfere file", "sending file done");
}
};
thread.start();
}
だから私の質問は:
- 使用している接続はチャットと同じ接続ですか (デフォルト ポート: 5222)?
- 関数をトリガー
sendfile(final String Receiver, final String Directory)
すると、受信者はいつ、どのように通知を受け取りますか?