0

私は電子メールの添付ファイルを処理しています。添付ファイル中に1つの問題に直面しています。問題は、添付ファイル付きのメールを送信したいということです。このパスに1つのファイルがあり、sdcard0、fgg、hh.htmlがあります。デバッグすると、ファイルFile file = new File(attachments.getString(i)); が表示 されます: /storage/sdcard0/fgg/hh.html です が、この後 if 条件に行かないのはなぜですか?

File file = new File(attachments.getString(i));
                        if (file.exists()) {
                            Uri uri = Uri.fromFile(file);
                            uris.add(uri);
                        }

ここに私のホールコードがあります

JSONArray attachments = parameters.getJSONArray("attachments");
        if (attachments != null && attachments.length() > 0) {
            ArrayList<Uri> uris = new ArrayList<Uri>();
            //convert from paths to Android friendly Parcelable Uri's
            for (int i=0; i<attachments.length(); i++) {
                try {
                    File file = new File(attachments.getString(i));
                    if (file.exists()) {
                        Uri uri = Uri.fromFile(file);
                        uris.add(uri);
                    }
                } catch (Exception e) {
                    LOG.e("EmailComposer", "Error adding an attachment: " + e.toString());
                }
            }
            if (uris.size() > 0) {
                emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
            }
        }
    } catch (Exception e) {
        LOG.e("EmailComposer", "Error handling attachments param: " + e.toString());
    }
4

3 に答える 3

1

ファイルへの URI にはトリプル スラッシュが必要です。

file:///storage/sdcard0/fgg/hh.html

ここでわかるように。しかし、私はおそらくうまくいかないので、文字列の "file:" 部分を削除してみてください:

File file = new File(attachments.getString(i).replace("file:","");
于 2013-07-31T07:57:46.743 に答える