java — регистрация активности с сохранением кнопки камеры во внешнюю базу данных

Я новичок в разработке Android. У меня есть действия в реестре, которые сохраняют пользовательский ввод во внешнюю базу данных с помощью сценария PHP, и это прекрасно работает.

Я решил добавить фотографию пользователя и сохранить ее также во внешнюю базу данных, чтобы она получала всю информацию о пользователе и снимки, сделанные с помощью кнопки камеры, в базу данных. Я хочу получить информацию, сделать снимок, вернуться к деятельности, а затем сохранить все в базе данных.

ДЖАВА:

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 for tittle
TextView textview = (TextView) findViewById(R.id.TextViewTitle);
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Regular.ttf");
textview.setTypeface(font);

//changing font for firstname and setting Editfirstname from activity
firstname = (EditText) findViewById(R.id.EditFirstName);
Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Light.ttf");
firstname.setTypeface(font1);

//changing font for email and setting Editemail from activity
email = (EditText) findViewById(R.id.EditEmail);
Typeface font2 = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Light.ttf");
email.setTypeface(font2);

//changing font for lastname and setting Editlastname from activity
lastname = (EditText) findViewById(R.id.EditLastName);
Typeface font3 = Typeface.createFromAsset(getAssets(), "fonts/OpenSans-Light.ttf");
lastname.setTypeface(font3);

//changing font for age and setting Editage from 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 listenersignup.setOnClickListener(new View.OnClickListener(){
InputStream is = null;
@Override
public void onClick(View arg0) {
//storing values inside edittexts inside the 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 the name value pair
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
//adding the 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 up connection inside the try block
try {
//setting up the default http client
HttpClient httpClient = new DefaultHttpClient();
//setting up the http post method and passing  the url for database and php file
//that servers as the link between the android app and database server
HttpPost httpPost = new HttpPost("http://myhost.com/demo.php");
//passing the nameValuePairs into the httpPost
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//get response
HttpResponse response = httpClient.execute(httpPost);
//setting up entity
HttpEntity entity = response.getEntity();
//setting up content inside an input stream reader
//lets setup the inputreader
is = entity.getContent();
//Displaying a toast message if the data is entered successfully
String msg = "Data entered successfully";
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}   //writing catch to handle the exceptions
catch (ClientProtocolException e)
{
Log.e("ClientProtocol", "Log_tag");
e.printStackTrace();
}catch(IOException e)
{
Log.e("Log_tag", "IOException");
e.printStackTrace();
}}
});}}

МОЙ 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 a 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 to electronically agree to the 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 a 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 into Player_info(FirstName, LastName, Email, Country, Age)        values('{$FirstName}','{$LastName}','{$Email}','{$Country}','{$Age}')");
mysql_close();
?>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector