からファイルサイズを取得することはできません。アンドロイドは、私は、ファイルサイズを決定するには、次の方法を持っているダイアログ
public static long getSize(String path) {
File file = new File(path);
if (file.exists()) {
long size = file.length();
return size;
} else {
Log.e("zero size", "the file size is zero!");
return 0;
}
は、今私は(コードが完了していない)は、以下の方法でダイアログを表示します:
public void gimmeDialog(String path_to_file) {
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Confirm");
TextView text = (TextView) dialog.findViewById(R.id.txtUploadInfo);
Button dialogButtonOK = (Button) dialog.findViewById(R.id.btnDialogOK);
long uploadSize = Send.getSize(path_to_file)/1024/1024;
text.setText("You are about to upload "
+ Long.toString(uploadSize)
+ " MB. You must accept the terms of service before you can proceed");
dialogButtonOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
問題はuploadSizeダイアログ関数の外に呼び出されたときに方法のgetSize()が正しいファイルサイズを返しても、常にゼロであるということです。指定された文字列のパスは正しいです。理由は何でしょうか?
P.S. Sendは私のクラス名です
は、1メガバイト、あなたのファイル大きいですか? –