2012-05-01 199 views
1

我正在開發一個應用程序,我必須通過電子郵件發送圖像。我成功地發送了電子郵件,但發送的附件大小爲0KB。我沒有得到什麼問題。下面,我張貼我的代碼。通過電子郵件發送的附件大小爲0KB

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.widget.Button; 

public class EtestActivity extends Activity { 
/** Called when the activity is first created. */ 
Button email; 
Intent in; 
private static final String TAG = "EmailLauncherActivity"; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    email = (Button)findViewById(R.id.email); 
    email.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      try { 
       in = new Intent(Intent.ACTION_SEND); 
       in.setType("image/jpeg"); 
       in.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/android.jpg")); 

       startActivity(Intent.createChooser(in, "Email...")); 
      } catch (Exception e) { 
       Log.e(TAG, "email sending failed", e); 
      }//catch 
     }//onClick 
    }); 
}//onCreate 
}//class 

回答

1

我也面臨着通過改變MIME類型解決的同樣的問題。

嘗試此in.setType( 「圖像/ JPG」);

+0

感謝Krishnakant,它工作。 – Nitish

+0

我面對的另一個問題是我使用了createchooser(),它顯示了所有能夠發送文件的應用程序的列表,但我只需要列出電子郵件客戶端。你能告訴我如何得到它嗎? – Nitish

+0

嘗試使用Intent.ACTION_SENDTO而不是Intent.ACTION_SEND –

0

當時您的手機是否已安裝到您的計算機上?連接到計算機時,SD卡可能無法訪問,因此實際上可能無法連接圖像。

+0

不,我已經給我的模擬器提供了SD卡支持,我保留了該映像。我單獨在手機上測試過的相同應用程序,並且還在名爲android.jpg的SD卡中保留了一個圖像。但是,我在這兩種情況下都面臨同樣的問題 – Nitish

相關問題