Header Ads

[Android] Feed back form via email.


FeedBack.java

package com.tssoft.dunghaysai;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class FeedBack extends Activity{
 
 EditText edtext ;
 Button btgui;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.layout_feedback);
  edtext =  (EditText)findViewById(R.id.edtext);
  btgui = (Button)findViewById(R.id.btgui);
  
  btgui.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
     Log.i("Send email", "");

         String[] TO = {"nguyenvanthanh9294@gmail.com"};
         Intent emailIntent = new Intent(Intent.ACTION_SEND);
         emailIntent.setData(Uri.parse("mailto:"));
         emailIntent.setType("message/rfc822");


         emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
         emailIntent.putExtra(Intent.EXTRA_SUBJECT, "feedback content");
         emailIntent.putExtra(Intent.EXTRA_TEXT, edtext.getText());

         try {
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
            finish();
            Log.i("Finished sending email...", "");
         } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(DonggopYkien.this, 
            "There is no email client installed.", Toast.LENGTH_SHORT).show();
         }
   }
  });
 }
 

}

layout_feedback.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:ads="http://schemas.android.com/apk/res-auto"   xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/leveldialog"
    android:weightSum="2"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10sp"
        android:layout_marginRight="10sp"
        android:layout_marginTop="10sp"
        android:background="#1DA6FC"
        android:gravity="center"
        android:padding="15sp"
        android:layout_weight="0"
        android:text="Feedback"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#ffffff"
        android:textSize="30sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10sp"
        android:layout_marginRight="10sp"
        android:gravity="center"
        android:layout_weight="1"
        android:text="please!fill your feedback here"
       android:textSize="16sp"
       android:textColor="#800000" />

    <EditText
        android:id="@+id/edtext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10sp"
        android:layout_marginRight="10sp"
        android:layout_marginTop="20sp"
        android:ems="10"
        android:layout_weight="1"
        android:lines="5" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btgui"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10sp"
        android:layout_marginLeft="10sp"
        android:background="@drawable/button_menuselector"
        android:layout_marginRight="10sp"
        android:layout_weight="0"
        android:text="Gửi" />

   
</LinearLayout>


Remember: add permission on your Manifest.xml


 <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

-----------The End ------------------



No comments:

Powered by Blogger.