ashish kha's Profile

About

 
Points: 0

Contact

 

ashish kha
February 7, 2016 · Public

ashish kha
February 7, 2016 · Public

please help sir

ashish kha
February 7, 2016 · Public

sir i had run this code on android emulator
i had connected to free host server ...but sir i have a query that the data is not working online

ashish kha
February 7, 2016 · Public

package com.example.database;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

public class Addinfo extends AppCompatActivity {


EditText Name,Email,Mobile;
String name,email,mobile;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_addinfo);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
Name=(EditText)findViewById(R.id.name);
Email=(EditText)findViewById(R.id.email);
Mobile=(EditText)findViewById(R.id.mobile);
}

public void save(View view)
{
name=Name.getText().toString();
email=Email.getText().toString();
mobile=Mobile.getText().toString();
BackgroundTask backgroundTask=new BackgroundTask();
backgroundTask.execute(name,email,mobile);

}
class BackgroundTask extends AsyncTask
{


String add_info_url;

@Override
protected String doInBackground(String... args) {
String name,email,mobile;
name=args[0];
email=args[1];
mobile=args[2];


try {
URL url=new URL(add_info_url);
HttpURLConnection httpURLConnection=(HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
OutputStream outputStream=httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter=new BufferedWriter(new OutputStreamWriter(outputStream,"UTF-8"));
String data= URLEncoder.encode("name","UTF-8")+"="+URLEncoder.encode(name,"UTF-8")+"&"+
URLEncoder.encode("email","UTF-8")+"="+URLEncoder.encode(email,"UTF-8")+"&"+
URLEncoder.encode("mobile","UTF-8")+"="+URLEncoder.encode(mobile,"UTF-8")+"&";
bufferedWriter.write(data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream =httpURLConnection.getInputStream();
inputStream.close();
httpURLConnection.disconnect();
return "one row inserted!!!";
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

@Override
protected void onPostExecute(String result) {


Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show();
}

@Override
protected void onPreExecute() {

add_info_url="http://ashishkha123.byethost17.com/add_info.php";


}

@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}

}

ashish kha
December 21, 2015 · Public

sir ... in my android studio ....in design mode in compiler below there is a pink mail folder so how should i remove it