Я пытаюсь создать приложение, которое отправляет электронное письмо с полями для редактирования текста;Затем он должен сделать фотографию и отправить электронное письмо с темой, текстом и фотографией, упомянутыми ранее.Я начал создавать две кнопки, одну для камеры и одну для электронной почты.Я, вероятно, буду использовать один для всего.Это только попытка, но я не нашел в интернете ничего, как связать вложение в JavaMail.
Можете ли вы мне помочь?Я действительно борюсь за решение.
Это основное занятие
public class MainActivity extends AppCompatActivity {
public EditText mEmail;
public EditText mSubject;
public EditText mMessage;
public Button mSend;
public Button takePicture;
protected static final int CAMERA_PIC_REQUEST = 0;
Bitmap thumbnail;
File pic;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mEmail = (EditText) findViewById(R.id.mailID);
mMessage = (EditText) findViewById(R.id.messageID);
mSubject = (EditText) findViewById(R.id.subjectID);
mSend = findViewById(R.id.send);
takePicture = findViewById(R.id.takePicture);
mSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sendMail();
}
});
takePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
});
}
private void sendMail() {
String mail = mEmail.getText().toString().trim();
String message = mMessage.getText().toString();
String subject = mSubject.getText().toString().trim();
JavaMailAPI javaMailAPI = new JavaMailAPI(this, mail, subject, message);
javaMailAPI.execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_PIC_REQUEST) {
thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.imageView1);
image.setImageBitmap(thumbnail);
try {
File root = Environment.getExternalStorageDirectory();
if (root.canWrite()) {
pic = new File(root, "pic.png");
FileOutputStream out = new FileOutputStream(pic);
thumbnail.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
}
} catch (IOException e) {
Log.e("BROKEN", "Could not write file " + e.getMessage());
}
}
}
}
Это макет:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
android:orientation="vertical"
tools:showIn="@layout/activity_main">
<EditText
android:id="@+id/mailID"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"/>
<EditText
android:layout_margin="10dp"
android:id="@+id/subjectID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject"/>
<EditText
android:layout_margin="10dp"
android:id="@+id/messageID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Message"/>
<Button
android:id="@+id/send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send" />
<Button
android:id="@+id/takePicture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Take Picture" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>