i new android development. have register activity saves user input external database using php script , works fine.
i decided add taking photo of user , save external database gets user info , picture taken camera button database. want info, take picture, come activity save database.
java:
public class registeractivity extends activity { edittext firstname, email, lastname, age; button signup; spinner country; @suppresslint("newapi") @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //set strict mode policy strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy); setcontentview(r.layout.activity_register); //changing font tittle textview textview = (textview) findviewbyid(r.id.textviewtitle); typeface font = typeface.createfromasset(getassets(), "fonts/opensans-regular.ttf"); textview.settypeface(font); //changing font firstname , setting editfirstname activity firstname = (edittext) findviewbyid(r.id.editfirstname); typeface font1 = typeface.createfromasset(getassets(), "fonts/opensans-light.ttf"); firstname.settypeface(font1); //changing font email , setting editemail activity email = (edittext) findviewbyid(r.id.editemail); typeface font2 = typeface.createfromasset(getassets(), "fonts/opensans-light.ttf"); email.settypeface(font2); //changing font lastname , setting editlastname activity lastname = (edittext) findviewbyid(r.id.editlastname); typeface font3 = typeface.createfromasset(getassets(), "fonts/opensans-light.ttf"); lastname.settypeface(font3); //changing font age , setting editage activity age = (edittext) findviewbyid(r.id.editage); typeface font4 = typeface.createfromasset(getassets(), "fonts/opensans-light.ttf"); age.settypeface(font4); country = (spinner) findviewbyid(r.id.spinnerselectcountrty); textview textview7 = (textview) findviewbyid(r.id.checkboxresponse); typeface font6 = typeface.createfromasset(getassets(), "fonts/opensans-light.ttf"); textview7.settypeface(font6); textview textview8 = (textview) findviewbyid(r.id.checkboxresponse1); typeface font7 = typeface.createfromasset(getassets(), "fonts/opensans-light.ttf"); textview8.settypeface(font7); //setup button activity signup = (button) findviewbyid(r.id.buttonsignup); //setup onclick listener signup.setonclicklistener(new view.onclicklistener(){ inputstream = null; @override public void onclick(view arg0) { //storing values inside edittexts inside string variables string firstname = ""+firstname.gettext().tostring(); string lastname = ""+lastname.gettext().tostring(); string email = ""+email.gettext().tostring(); string country = country.getselecteditem().tostring().trim(); string age = ""+age.gettext().tostring(); //setting name value pair list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(1); //adding strings variables inside stringvaluepairs namevaluepairs.add(new basicnamevaluepair("firstname", firstname)); namevaluepairs.add(new basicnamevaluepair("lastname", lastname)); namevaluepairs.add(new basicnamevaluepair("email", email)); namevaluepairs.add(new basicnamevaluepair("country", country)); namevaluepairs.add(new basicnamevaluepair("age", age)); //setting connection inside try block try { //setting default http client httpclient httpclient = new defaulthttpclient(); //setting http post method , passing url database , php file //that servers link between android app , database server httppost httppost = new httppost("http://myhost.com/demo.php"); //passing namevaluepairs httppost httppost.setentity(new urlencodedformentity(namevaluepairs)); //get response httpresponse response = httpclient.execute(httppost); //setting entity httpentity entity = response.getentity(); //setting content inside input stream reader //lets setup inputreader = entity.getcontent(); //displaying toast message if data entered string msg = "data entered successfully"; toast.maketext(getapplicationcontext(), msg, toast.length_long).show(); } //writing catch handle exceptions catch (clientprotocolexception e) { log.e("clientprotocol", "log_tag"); e.printstacktrace(); }catch(ioexception e) { log.e("log_tag", "ioexception"); e.printstacktrace(); } } }); } }
my xml:
<scrollview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollview01" android:theme="@style/apptheme" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="vertical"> <linearlayout android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="fill_parent"> <!--put form controls here--> <textview android:id="@+id/textviewtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/text_color3" android:text="@string/feedbacktitle" android:textsize="20sp"> </textview> <edittext android:id="@+id/editfirstname" android:layout_height="wrap_content" android:hint="enter first name" android:inputtype="textpersonname" android:textcolor="@color/text_color2" android:textsize="10sp" android:layout_width="fill_parent" android:layout_margintop="30dp"> </edittext> <edittext android:id="@+id/editlastname" android:layout_height="wrap_content" android:textcolor="@color/text_color2" android:hint="enter last name" android:inputtype="textpersonname" android:textsize="10sp" android:layout_width="fill_parent"> </edittext> <edittext android:id="@+id/editemail" android:layout_height="wrap_content" android:hint="@string/feedbackemail" android:textcolor="@color/text_color2" android:inputtype="textemailaddress" android:layout_width="fill_parent" android:textsize="10sp"> </edittext> <edittext android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="age" android:textcolor="@color/text_color2" android:inputtype="number" android:ems="10" android:id="@+id/editage" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/text_color2" android:textappearance="?android:attr/textappearancesmall" android:text="please select team" android:id="@+id/textselectcountry" android:layout_margintop="30dp" /> <spinner android:id="@+id/spinnerselectcountrty" android:layout_height="wrap_content" android:prompt="@string/feedbacktype" android:textcolor="@color/text_color2" android:layout_width="fill_parent" android:entries="@array/feedbacktypelist" android:layout_margintop="20dp"> </spinner> <checkbox android:layout_height="wrap_content" android:text="please check box electronically agree tournaments terms" android:id="@+id/checkboxresponse1" android:textcolor="@color/text_color2" android:layout_width="fill_parent" android:layout_margintop="20dp" /> <checkbox android:id="@+id/checkboxresponse" android:layout_height="wrap_content" android:textcolor="@color/text_color2" android:text="@string/feedbackresponse" android:layout_width="fill_parent" android:layout_margintop="20dp"> </checkbox> <button android:id="@+id/buttonphoto" android:layout_height="wrap_content" android:text="take photo" android:onclick="sendfeedback" android:textcolor="@color/text_color2" android:layout_below="@id/checkboxresponse" android:layout_width="152dp" android:layout_margintop="20dp"> </button> <button android:id="@+id/buttonsignup" android:layout_height="wrap_content" android:text="@string/feedbackbutton" android:layout_below="@id/buttonphoto" android:textcolor="@color/text_color2" android:onclick="sendfeedback" android:layout_width="152dp" android:layout_margintop="20dp"> </button> </linearlayout> </scrollview>
php:
<?php $con=mysql_connect('something.com','username','password'); mysql_select_db("dbname", $con); $firstname=$_post['firstname']; $lastname=$_post['lastname']; $email=$_post['email']; $country=$_post['country']; $age=$_post['age']; mysql_query("insert player_info(firstname, lastname, email, country, age) values('{$firstname}','{$lastname}','{$email}','{$country}','{$age}')"); mysql_close(); ?>