protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if ( resultCode == RESULT_OK ) { Uri uri = data.getData(); if( uri != null ) { iv = (ImageView)this.findViewById(R.id.imageView1); iv.setImageURI( uri );
String url = "file://sdcard/sunset.jpg";
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
shareIntent.putExtra("address", "5554");
shareIntent.putExtra("sms_body", "mms test");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
startActivity(shareIntent) ;
程式可以執行,但是無法附加檔案,會出現ERROR的TOAST
"Sorry,you cannot add this picture to your message."
您說的部份我會去嘗試,謝謝
另外,修改上述程式碼,我可以直接將gallery內的圖檔附加至MMS的activity,但是圖檔路徑變成content://media/external/images/media/2,請問老師是否有方法可以透過上述路徑轉換成檔案的絕對路徑(或將圖檔的絕對路徑轉成context://開頭的路徑)?此外,當出現MMS SEND的activity後有方法直接SEND MMS而不需要使用者點擊傳送按鈕嗎?
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra("address", "5554");
sendIntent.putExtra("sms_body", "mms test");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(uploadFile));
startActivity(sendIntent);
其中uploadFile是透過Intent.ACTION_PICK及onActivityResult取得
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if ( resultCode == RESULT_OK )
{
Uri uri = data.getData();
if( uri != null )
{
iv = (ImageView)this.findViewById(R.id.imageView1);
iv.setImageURI( uri );
uploadFile = uri.toString();
uploadfileText = (TextView) findViewById(R.id.textView1);
uploadfileText.setText("檔案路徑: \n"+uploadFile);
}
else
{
uploadfileText = (TextView) findViewById(R.id.textView1);
uploadfileText.setText("無效的檔案路徑 !!");
}
}
else
{
uploadfileText = (TextView) findViewById(R.id.textView1);
uploadfileText.setText("取消選擇檔案 !!");
}
}
}