也许这是一个愚蠢的问题,但我正在通过使用文件选择器选择文件来执行上传文件功能,但我不知道如何获取文件路径。
请帮忙。
public class UploadToServer extends Activity {
EditText fileSaveLoad;
TextView messageText;
Button uploadButton;
int serverResponseCode = 0;
ProgressDialog dialog = null;
String upLoadServerUri = null;
private Button mLoadButton;
private Button mSaveButton;
/** Sample filters array */
final String[] mFileFilter = { "*.*", ".jpeg", ".txt", ".png" };
/********** File Path *************/
final String uploadFilePath = "/mnt/sdcard/";
final String uploadFileName = "test.png";
//fileSaveLoad.getText().toString();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_upload_to_server);
fileSaveLoad = (EditText)findViewById(R.id.fileSaveLoad);
uploadButton = (Button)findViewById(R.id.uploadButton);
messageText = (TextView)findViewById(R.id.messageText);
mLoadButton = (Button) findViewById(R.id.button_load);
mSaveButton = (Button) findViewById(R.id.button_save);
messageText.setText("Uploading file path :- '/mnt/sdcard/"+uploadFileName+"'");
/************* Php script path ****************/
upLoadServerUri = "http://192.168.0.106/UploadToServer.php";
uploadButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog = ProgressDialog.show(UploadToServer.this, "", "Uploading file...", true);
new Thread(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
messageText.setText("uploading started.....");
}
});
uploadFile(uploadFilePath + "" + uploadFileName);
}
}).start();
}
});
mLoadButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
new FileSelector(UploadToServer.this, FileOperation.LOAD, mLoadFileListener, mFileFilter).show();
}
});
mSaveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
new FileSelector(UploadToServer.this, FileOperation.SAVE, mSaveFileListener, mFileFilter).show();
}
});
}
OnHandleFileListener mLoadFileListener = new OnHandleFileListener() {
@Override
public void handleFile(final String filePath) {
Toast.makeText(UploadToServer.this, "Load: " + filePath, Toast.LENGTH_SHORT).show();
}
};
OnHandleFileListener mSaveFileListener = new OnHandleFileListener() {
@Override
public void handleFile(final String filePath) {
Toast.makeText(UploadToServer.this, "Save: " + filePath, Toast.LENGTH_SHORT).show();
}
};
我想问一下,有什么办法可以得到filePath
OnHandleFileListener mLoadFileListener = new OnHandleFileListener() {
@Override
public void handleFile(final String filePath) {
Toast.makeText(UploadToServer.this, "Load: " + filePath, Toast.LENGTH_SHORT).show();
}
};
至
final String uploadFileName = "test.png";