2013-04-03 4 views
6

मैं सामग्री प्रदाता का उपयोग करके अनुलग्नकों के साथ एक ईमेल भेज रहा हूं।अटैचमेंट के साथ एंड्रॉइड भेजने वाला ईमेल हमेशा काम नहीं करता

  1. सबसे पहले, मैं फ़ाइलों को कैश डीआईआर में लिखता हूं।
  2. फिर मैं सामग्री प्रदाता
  3. द्वारा प्रत्येक फ़ाइल के लिए एक यूआरएल के साथ ईमेल बना देता हूं, फिर मैं ACTION_SEND_MULTIPLE मंशा के साथ एक नई गतिविधि शुरू करता हूं।
  4. मैं जीमेल चुनता हूं और फिर भेजें बटन दबाता हूं।

यह कभी-कभी काम करता है, ऐसा लगता है कि यह थोड़ी देर में पहली बार काम करता है, लेकिन बाद की कोशिशों के बाद काम नहीं कर रहा है ... लेकिन यह हमेशा ऐसा नहीं होता है।

जब यह काम नहीं करता है तो ईमेल जीमेल में भेजने में फंस गया है। यह 2.3.3 और 4.0.1 पर होता है, जीमेल क्लाइंट में मेल खोलना और प्रेषण बटन मारना अक्सर संदेश को लगभग तुरंत वितरित करने का कारण बनता है, लेकिन हर बार नहीं।

Google ड्राइव के साथ इरादे खोलना जीमेल के समान व्यवहार है।

बिल्ट इन एक्सचेंज मेल क्लाइंट के साथ इरादा खोलना हमेशा काम करता है।

यहाँ ई-मेल भेजने के लिए कोड है:

  Intent sendIntent = new Intent(Intent.ACTION_SEND_MULTIPLE); 
      sendIntent.putExtra(Intent.EXTRA_EMAIL, exportParams.emailAddresses); 
      sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Leader Activity Report"); 
      sendIntent.putExtra(Intent.EXTRA_TEXT, "Leader Activity Report, see attached file."); 
      Uri fileUri = CachedFileProvider.createFileUri(result.fileName); 
      if (L.dbg()) 
       L.dbg("Using uri:" + fileUri.toString()); 
      ArrayList<Uri> uris = new ArrayList<Uri>(); 
      uris.add(fileUri); 
      Uri fileUri2 = CachedFileProvider.createFileUri(result.fileNameDayByDay); 
      uris.add(fileUri2); 
      if (L.dbg()) 
       L.dbg("Using uri2:" + fileUri2.toString()); 
      sendIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); 
      sendIntent.setType("text/plain"); 
      parent.startActivity(sendIntent); 

यहाँ सामग्री प्रदाता

public class CachedFileProvider extends ContentProvider { 

private static final String CLASS_NAME = "CachedFileProvider"; 
public static final String AUTHORITY = "com.josh.lll.file.provider"; 

private UriMatcher uriMatcher; 

@Override 
public boolean onCreate() { 
    uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); 
    uriMatcher.addURI(AUTHORITY, "*", 1); 
    return true; 
} 


@Override 
public ParcelFileDescriptor openFile(Uri uri, String mode) 
     throws FileNotFoundException { 
    try { 
     String LOG_TAG = CLASS_NAME + " - openFile"; 
     Log.v(LOG_TAG, 
       "Called with uri: '" + uri + "' - " + uri.getLastPathSegment()); 
     switch (uriMatcher.match(uri)) { 
     case 1: 
      String fileLocation = getContext().getCacheDir() + File.separator 
        + uri.getLastPathSegment(); 
      Log.i(CLASS_NAME,"Returning file :"+fileLocation); 
      ParcelFileDescriptor pfd = ParcelFileDescriptor.open(new File(
        fileLocation), ParcelFileDescriptor.MODE_READ_ONLY); 
      return pfd; 
     default: 
      Log.v(LOG_TAG, "Unsupported uri: '" + uri + "'."); 
      throw new FileNotFoundException("Unsupported uri: " 
        + uri.toString()); 
     } 
    } catch (FileNotFoundException t) { 
     Bug.major(this, t, "Could not return file descriptor"); 
     throw t; 
    } catch (RuntimeException t) { 
     Bug.major(this, t, "Could not return file descriptor"); 
     throw t; 
    } catch (Error t) { 
     Bug.major(this, t, "Could not return file descriptor"); 
     throw t; 
    } 
} 

public static String createFullyQualifiedFileName(Context c, String fileNamePart) { 
    File cacheDir = c.getCacheDir(); 
    Log.i(CLASS_NAME,"Using cache dir:"+cacheDir); 
    return cacheDir + File.separator + fileNamePart; 
} 

public static Uri createFileUri(String fileNamePart) { 
    return Uri.parse("content://" + AUTHORITY + "/"+ fileNamePart); 
} 

public int update(Uri uri, ContentValues contentvalues, String s, 
     String[] as) { 
    return 0; 
} 

@Override 
public int delete(Uri uri, String s, String[] as) { 
    return 0; 
} 

@Override 
public Uri insert(Uri uri, ContentValues contentvalues) { 
    return null; 
} 

@Override 
public String getType(Uri uri) { 
    return null; 
} 

@Override 
public Cursor query(Uri uri, String[] projection, String s, String[] as1, 
     String s1) { 
    return null; 
} 

}

दोनों सफल और के लिए है 'ठप' ईमेल के बाद लॉग संदेश भेजता है जीमेल द्वारा मुद्रित है:

04-03 22:17:35.027: I/Gmail(13206): >>>>> Attachment uri: content://com.josh.lll.file.provider/report_20100401_20130402_LeadetJosh_3_1364980653516.csv 
04-03 22:17:35.035: I/Gmail(13206): >>>>>   type: text/plain 
04-03 22:17:35.035: I/Gmail(13206): >>>>>   size: 0 
04-03 22:17:35.054: I/Gmail(13206): >>>>> Attachment uri: content://com.josh.lll.file.provider/backup_20100401_20130402_LeadetJosh_3_1364980653516_day_by_day.lll 
04-03 22:17:35.054: I/Gmail(13206): >>>>>   type: text/plain 
04-03 22:17:35.054: I/Gmail(13206): >>>>>   size: 0 
+0

यदि मैं प्रत्येक फ़ाइल नाम पर एक अद्वितीय स्ट्रिंग जोड़ता हूं तो यह समस्या दूर हो जाती है। यही वह नहीं है जो मैं करना चाहता हूं। – placebojim

+0

हाँ। असल में यह काफी दूर नहीं जाता है, यह कम संभावना है। – placebojim

+2

अरे, क्या आपने इस मुद्दे को हल करने का प्रबंधन किया था? मैं कुछ इसी तरह से चल रहा हूं, लेकिन मेरे मामले में ईमेल भेजे जाते हैं लेकिन अनुलग्नक गुम हैं। मुझे एक ही लॉग संदेश मिलते हैं, लेकिन आकार सही हैं। – Pin

उत्तर

-3

एक इलाज मिला:

  • जीमेल को अक्षम करें।
  • फ़ैक्टरी डिफ़ॉल्ट पर रीसेट करें।
  • फोन को बंद और पीछे के रूप में रीबूट करें।
  • जीमेल सक्षम करें।

अनुलग्नकों के लिए काम करना चाहिए फिर से

1

इसे पसंद/डेटा/एप्लिकेशन या/प्रणाली सिस्टम फ़ोल्डर में संग्रहीत फ़ाइलों के लिए होता है।

इसके लिए वर्कअराउंड है: उन फ़ाइलों को एसडीकार्ड स्थान में कॉपी करें और उन्हें वहां से संलग्न/उपयोग करें।

संबंधित मुद्दे