如何通过电子邮件或短信在Android中发送照片和视频?

时间:2015-11-26 07:48:35

标签: android android-sqlite

以下是我发送危险短信和电子邮件的代码..我想发送视频或照片。怎么做??

public class TriggerNotifManager {

private static final String MESSGAE_BODY = "in danger.Location is : ";;
private static final String VCid = "noreplyvcare@gmail.com";
private static final String VCpass = "vcx2015+";
private static final String subject = "I am in Danger";
private static final String noReply = "This is a system generated email. Please Contact the person in danger."
                                        +"\n"+"Thank You,\n"+"VCare";

List<Contact> contactList;
GetLocationManager myLoc;
SendSMSManager mySMS;
SendMailManager myEmail;
String name,latlong,address;

public TriggerNotifManager(String name,List<Contact> contactList,GetLocationManager myLoc){
    this.contactList=contactList;
    this.myLoc=myLoc;
    mySMS=new SendSMSManager();
    myEmail=new SendMailManager();

    latlong=myLoc.getLatLong();
    address=myLoc.getCompleteAddress();
    this.name=name;
}

public void sendDangerSMS(){

    for(int i=0;i<contactList.size();i++)
    {

        String phone=(contactList.get(i)).getPhoneNumber();
        mySMS.sendSMSMessage(phone,name+" : HELP !! "+"I am "+MESSGAE_BODY+latlong+"\n"+address);


    }
}

public void sendDangerMail(){

    for(int i=0;i<contactList.size();i++)
    {
        String recipient=(contactList.get(i)).getEmail();
    // {senderID,senderPass,subject,body,recipientID}
        myEmail.execute(VCid,VCpass,subject,"HELP !! "+name+" is "+MESSGAE_BODY+latlong+"\n"+address+"\n"+noReply,recipient);
    }
}

public void sendSafeSMS(){

    for(int i=0;i<contactList.size();i++)
    {

        String phone=(contactList.get(i)).getPhoneNumber();
        mySMS.sendSMSMessage(phone,name+" : I am Safe ");


    }
}
}

这是我的警报页面代码..在这个我在MenuOption中启动相机..它需要照片,但我不知道如何发送它。请建议执行此操作的代码

public void onAlertClick(View v)
{
    myNotif.sendDangerSMS();
    myNotif.sendDangerMail();

}
@Override  
public boolean onCreateOptionsMenu(Menu menu) {  
    // Inflate the menu; this adds items to the action bar if it is present.  
    getMenuInflater().inflate(R.menu.alert, menu);//Menu Resource, Menu  
    return true;  
}  
@Override  
public boolean onOptionsItemSelected(MenuItem item) {  
    switch (item.getItemId()) {  
        case R.id.item1:  
            Uri uri2 = Uri.parse("https://www.google.co.in/search?q=police%20stations+near+me");
            Intent i2 = new Intent(Intent.ACTION_VIEW, uri2); 
            startActivity(i2); 
        break;     
       case R.id.item2: 
            Uri uri1 = Uri.parse("https://www.google.co.in/search?q=hospitals+near+me");
            Intent i1 = new Intent(Intent.ACTION_VIEW, uri1); 
            startActivity(i1);
          break;
       case R.id.item3:
          Intent i3 = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
          startActivity(i3);


          default:  
            break; 
    }  
    return true;
}
}

1 个答案:

答案 0 :(得分:0)

使用以下代码发送邮件

String filelocation="/mnt/sdcard/contacts_sid.vcf";    
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"asd@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, filelocation);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));  

在此处回答链接:How to send an email with a file attachment in Android