मैं अपने एंड्रॉइड ऐप में एक ईमेल में download.pdf नामक एक पीडीएफ फाइल संलग्न करने की कोशिश कर रहा हूं। मैं पहले फाइल को एसडीकार्ड में कॉपी कर रहा हूं और फिर इसे ईमेल संलग्न कर रहा हूं।एंड्रॉइड ऐप से किसी ईमेल को पीडीएफ संलग्न करना - फ़ाइल का आकार शून्य
मैं प्रासंगिक नहीं हूं, लेकिन मैं एक आकाशगंगा टैब डिवाइस पर परीक्षण कर रहा हूं। बाह्य भंडारण पथ देता है इस प्रकार है mnt/sdcard/
मेरे कोड है:
public void sendemail() throws IOException {
CopyAssets();
String emailAddress[] = {""};
File externalStorage = Environment.getExternalStorageDirectory();
Uri uri = Uri.fromFile(new File(externalStorage.getAbsolutePath() + "/" + "download.pdf"));
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddress);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Text");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send email using:"));
}
public void CopyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
} catch (IOException e) {
Log.e("tag", e.getMessage());
}
for(String filename : files) {
InputStream in = null;
OutputStream out = null;
if (filename.equals("download.pdf")) {
try {
System.out.println("Filename is " + filename);
in = assetManager.open(filename);
File externalStorage = Environment.getExternalStorageDirectory();
out = new FileOutputStream(externalStorage.getAbsolutePath() + "/" + filename);
System.out.println("Loacation is" + out);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch(Exception e) {
Log.e("tag", e.getMessage());
}
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
}
समस्या यह है कि जिस फ़ाइल को जुड़ा हुआ है आकार में 0 बाइट्स है। क्या कोई यह बता सकता है कि क्या गलत हो सकता है?
संपादित
मैं देख सकता हूँ कि फ़ाइल डिवाइस पर सहेज लिया गया है कि अगर मैं सेटिंग्स में लग रही है, इसलिए यह कैसे मैं ईमेल के लिए फ़ाइल संलग्न कर रहा हूँ चारों ओर एक समस्या होना चाहिए। त्रुटि के लिए लॉग इन मैं देख रहा हूँ:
gMail Attachment URI: file:///mnt/sdcard/download.pdf
gMail type: application/pdf
gmail name: download.pdf
gmail size: 0
संपादित
अगर इस आकाशगंगा टैब पर एक बग है सोच? अगर मैं एक पीडीएफ दर्शक (मेरे ऐप से) के माध्यम से फ़ाइल खोलता हूं तो एक जीमेल ईमेल से अटैच करने का प्रयास करें, आकार फिर से 0 है। क्या कोई सत्यापित कर सकता है?
धन्यवाद।
अपने एप्लिकेशन को SD कार्ड पर पहुंच की अनुमति है? –
हां - मैनिफेस्ट में - <उपयोग-अनुमति एंड्रॉइड: नाम = "android.permission.WRITE_EXTERNAL_STORAGE" /> – GuybrushThreepwood
क्या आपने अपने 'sdcard' में पीडीएफ फ़ाइल आकार की जांच की थी जिसे आपने' copyAssets() 'विधि का उपयोग करके कॉपी किया था। – Praveenkumar