问题描述:

Here is my code to send Danger SMS and Email.. I want to send video or photos along with this. How to do that??

public class TriggerNotifManager {

private static final String MESSGAE_BODY = "in danger.Location is : ";;

private static final String VCid = "[email protected]";

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 ");

}

}

}

Here is my Alert page code.. In this I launch camera in MenuOption.. It takes Photos but i don't know how to send it. Please suggest code for doing this

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;

}

}

网友答案:

Use the below code to sent a mail

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[] = {"[email protected]"};
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..."));  

Answer link here: How to send an email with a file attachment in Android

相关阅读:
Top