Manifest
<?xml version="1.0" encoding="utf-8"?>
package="com.example.urlaubsbilder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Bilder"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.LukasMike.kuendigung.URLAUB" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Bilder Klasse
package com.example.urlaubsbilder;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class Bilder extends Activity implements View.OnClickListener{
EditText personenEmail, gedanken ;
String name;
String emailAdresse;
Button sendeEmail,bildMachen;
Intent emailIntent;
final static int cameraData=0;
Bitmap bmp;
Uri image;
ImageView iv;
int CAMERA_PIC_REQUEST =0;
String path ;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initialize();
sendeEmail.setOnClickListener(this);
bildMachen.setOnClickListener(this);
}
private void initialize() {
// TODO Auto-generated method stub
personenEmail = (EditText) findViewById(R.id.etEmailadresse);
gedanken = (EditText) findViewById(R.id.etGrund);
bildMachen = (Button) findViewById(R.id.bBildAufnehmen);
sendeEmail = (Button) findViewById(R.id.bSendeEmail);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()){
case R.id.bSendeEmail:
convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
String emailaddress[] = { emailAdresse };
String message = "Sehr geehrte Damen und Herren, "
+ '\n'+ name;
// emailIntent = new Intent(android.content.Intent.ACTION_SEND);
// emailIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
// startActivityForResult(emailIntent, cameraData);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Kündigung meines Zeitschriftenvertrags" );
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_STREAM, image);
emailIntent.setType(path);
// emailIntent.putExtra(Intent.EXTRA_STREAM,image);
//emailIntent.setType("image");
//emailIntent.putExtra(android.content.Intent.E
startActivity(emailIntent);
break;
case R.id.bBildAufnehmen:
emailIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(emailIntent, CAMERA_PIC_REQUEST);
break;
}
}
private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() {
// TODO Auto-generated method stub
emailAdresse = personenEmail.getText().toString();
name = gedanken.getText().toString();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if( requestCode == CAMERA_PIC_REQUEST)
{
data.getExtras();
bmp = (Bitmap) data.getExtras().get("data");
iv =(ImageView) findViewById(R.id.bBildAufnehmen);
iv.setImageBitmap(bmp);
image = data.getData();
path = getPath(image); //Dein Pfad zum Bild im Dateisystem
}
/* if (resultCode==RESULT_OK){
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
iv.setImageBitmap(bmp);
image = getImageUri(this, bmp);
// image = (Uri) extras.get("data");
// Uri imageUri = Uri.writeToParcel(out, bmp);
}*/
}
/* public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
return Uri.parse(path);
}*/
public String getPath(Uri uri)
{
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if (cursor == null) return null;
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String s=cursor.getString(column_index);
cursor.close();
return s;
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
android:orientation="vertical"
android:layout_width="match_parent"
android:weightSum="100"
android:layout_height="match_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="323dp" >
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:text="Die Emailadresse des Unternehmens:"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content"
android:hint="E-Mail"
android:layout_width="match_parent" android:id="@+id/etEmailadresse">
</EditText>
<TextView android:text="Urlaubsgedanken:"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content"
android:hint="Dieser Text wird genauso übernommen wie Sie ihn eintippen"
android:layout_width="match_parent" android:id="@+id/etGrund"></EditText>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="60"
android:orientation="vertical" >
<Button
android:id="@+id/bBildAufnehmen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="BildAufnehmen" />
<Button
android:id="@+id/bSendeEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Sende Email" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.74"
android:src="@drawable/ic_launcher" />
</LinearLayout>
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.