Basically I want to have a button to start a new activity after login.
I found that I was not able to call the StartActivity() as what I did before in the login page.Please guide
This is the login page where I used StartActivity(this,sth.class)sucessfully
public class Login extends Activity
{
/** Called when the activity is first created. */
Button login;
String name="",pass="";
EditText username,password;
TextView tv;
byte[] data;
HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
InputStream inputStream;
SharedPreferences app_preferences ;
List<NameValuePair> nameValuePairs;
CheckBox check;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
username = (EditText) findViewById(R.id.username);
password = (EditText) findViewById(R.id.password);
login = (Button) findViewById(R.id.login);
check = (CheckBox) findViewById(R.id.check);
String Str_user = app_preferences.getString("username","0" );
String Str_pass = app_preferences.getString("password", "0");
String Str_check = app_preferences.getString("checked", "no");
if(Str_check.equals("yes"))
{
username.setText(Str_user);
password.setText(Str_pass);
check.setChecked(true);
}
login.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
name = username.getText().toString();
pass = password.getText().toString();
String Str_check2 = app_preferences.getString("checked", "no");
if(Str_check2.equals("yes"))
{
SharedPreferences.Editor editor = app_preferences.edit();
editor.putString("username", name);
editor.putString("password", pass);
editor.commit();
}
if(name.equals("") || pass.equals(""))
{
Toast.makeText(Login.this, "Blank Field..Please Enter", Toast.LENGTH_LONG).show();
}
else
{
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://fyptest.comyr.com/main.php");
// Add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data)) )
{
buffer.append(new String(data, 0, len));
}
inputStream.close();
}
catch (Exception e)
{
Toast.makeText(Login.this, "error"+e.toString(), Toast.LENGTH_LONG).show();
}
if(buffer.charAt(0)=='Y')
{
Toast.makeText(Login.this, "login successfull", Toast.LENGTH_LONG).show();
Move_to_next();
}
else
{
Toast.makeText(Login.this, "Invalid Username or password", Toast.LENGTH_LONG).show();
}
}
}
});
check.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// Perform action on clicks, depending on whether it's now checked
SharedPreferences.Editor editor = app_preferences.edit();
if (((CheckBox) v).isChecked())
{
editor.putString("checked", "yes");
editor.commit();
}
else
{
editor.putString("checked", "no");
editor.commit();
}
}
});
}
public void Move_to_next()
{
//may perform checking based on ID
startActivity(new Intent(this, MainMenu.class));
}
But this, my startActivity is being underlined in red
public class MainMenu extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
Button new_folder = (Button)findViewById(R.id.new_folder);
new_folder.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
// show another class
startActivity(new Intent(this,Folder_Details.class));
}
});
}
}
It shows "The constructor Intent(new View.OnClickListener(){}, Class) is undefined" and "Remove arguments to match Intent()" options
I have included the <Activity></Activity> in Manifest. And the code showed above, imports are cut off
Yes this is because, you are trying to use "this" with refernce to your button instead of your activity. You have to replace it like this,
Instead of startActivity(new Intent(this, Folder_Details.class));
do this,
startActivity(new Intent(MainMenu.this, Folder_Details.class));
Modify it as
startActivity(new Intent(MainMenu.this,Folder_Details.class));
You are using a View.OnClickListener instead of a Context instance.
startActivity(new Intent(MainMenu.this,Folder_Details.class));
Related
I have android app for login, when user gives login details that data have to pass in multiple activities.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username=(EditText)findViewById(R.id.user_name);
passwrd=(EditText)findViewById(R.id.Pass_word);
login=(Button)findViewById(R.id.Login);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String email = username.getText().toString();
String password = passwrd.getText().toString();
new Mytask().execute(email, password);
}
});
}
I want to pass email and password to multiple activities..
I just tried Bundle.
I stored email value as "name".
And i just passed the value to another activity(Below code).
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_testpage);
Entertext = (EditText) findViewById(R.id.tex_id);
Submit = (Button) findViewById(R.id.sub_mit);
Submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String Text = Entertext.getText().toString();
Intent i = getIntent();
Bundle b = i.getBundleExtra("personBdl");
String name = b.getString("name");
new Mytask().execute(name,Text);
}
});
private class Mytask extends AsyncTask<String, Integer, String> {
#Override
protected String doInBackground(String... params) {
StringBuilder dta = null;
try {
URL url = new URL("http://xxxyyy.com/insert.php?user=" + params[0] + "&value=" + params[1]);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
int statusCode = urlConnection.getResponseCode();
if (statusCode == 200) {
InputStream it = new BufferedInputStream(urlConnection.getInputStream());
InputStreamReader read = new InputStreamReader(it);
BufferedReader buff = new BufferedReader(read);
dta = new StringBuilder();
String chunks;
while ((chunks = buff.readLine()) != null) {
dta.append(chunks);
}
} else {
//Handle else
}
return dta.toString();
} catch (ProtocolException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
Email has passed as "name"(bundle).
"name" value passed as params[0] to my php file.
But params[0] not passed to my php file.
Could you please help me with this. Thank you.
You should probably use SharedPreferences instead of Bundle.
Save data like this:
SharedPreferences sPref;
sPref = getPreferences(MODE_PRIVATE);
Editor ed = sPref.edit();
ed.putString("email", etText.getText().toString());
ed.putString("password", etText.getText().toString());
ed.commit();
And get it in your activities like this:
sPref = getPreferences(MODE_PRIVATE);
String email = sPref.getString("email", "");
String password = sPref.getString("password", "");
etText.setText(savedText);
And I also recommend you to use it in separate thread.
Here's the code where I get to have the SharedPreferences:
public class MainActivity2 extends Activity {
Button b;
EditText et;
TextView tv;
HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
ProgressDialog dialog = null;
String rfid, getPref;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
b = (Button)findViewById(R.id.loginnext);
et = (EditText)findViewById(R.id.rfid);
tv = (TextView)findViewById(R.id.tv);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog = ProgressDialog.show(MainActivity2.this, "",
"Validating user...", true);
new Thread(new Runnable() {
public void run() {
login();
}
}).start();
}
});
}
void login(){
try{
SharedPreferences preferences = getSharedPreferences(getPref, Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = preferences.edit();
httpclient=new DefaultHttpClient();
httppost= new HttpPost("http://usamobileapp.pe.hu/webservice/check.php");
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username",et.getText().toString().trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response : " + response);
runOnUiThread(new Runnable() {
public void run() {
tv.setText("Response from PHP : " + response);
dialog.dismiss();
}
});
if(response.equalsIgnoreCase("User Found")){
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(MainActivity2.this,"Login Success", Toast.LENGTH_SHORT).show();
editor.putString("rfid" ,rfid);
editor.commit();
}
});
startActivity(new Intent(MainActivity2.this, MainActivity3Activity.class));
}else{
showAlert();
}
}catch(Exception e){
dialog.dismiss();
System.out.println("Exception : " + e.getMessage());
}
}
This is where I'd like the get the Registration ID entered by the user and use it in all activities of the app.
Here is the code to check whether I get to have the SharedPreferences correctly. It displays it through I text view. I wonder why it would not show up. Did I do the SharePreferences correctly?
public class ViewGradesActivity extends ActionBarActivity {
TextView viewPref;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_grades);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
String get = settings.getString("rfid", "");
viewPref = (TextView) findViewById(R.id.tv);
viewPref.setText(get);
}
}
By the way, the code above is from another class.
Thanks for the help in advance.
You are receiving this error because you are writing to a different SharedPreferences than you are reading from. If you are using default SharedPreferences, make sure you read and write to the default preferences.
// Read the String from SharedPreferences
String awesomeString = PreferenceManager.getDefaultSharedPreferences(context).getString("key", "");
// Write the String to SharedPreferences
PreferenceManager.getDefaultSharedPreferences(context)
.edit().putString("key", awesomeString).commit();
That's because you don't read and write the preferences in the same preference file.
To write you use:
SharedPreferences preferences = getSharedPreferences(getPref, Context.MODE_PRIVATE);
To read you use:
PreferenceManager.getDefaultSharedPreferences(this);
So you write you preferences in a file getPref (which is null according to your code, don't you get any error?) but you read your preferences in the default file provided by the Android API.
Are you sure that you put any value in rfid? Here
public void run() {
Toast.makeText(MainActivity2.this,"Login Success", Toast.LENGTH_SHORT).show();
editor.putString("rfid" ,rfid);
editor.commit();
}
I think rfid is null. I did not find any place where you are initializing it.
Put rfid in toast or log it and you will see.
And as everybody else say you have to use default shared preferences in both classes. Here you can find why Difference between getDefaultSharedPreferences and getSharedPreferences
Hi I'm new to android and have task to create a login page that will connect with server and check user exist using http Get and AsyncTask and PHP API for this is ready. i went through few tutorials on AsyncTask and i understood but i m not sure how to work with http Get and AsyncTask. can anyone please help how to link both and create login page.
P.S: i have two EditText to accept username and password and two Buttons one for login and other for register and have corresponding DB as well.
This is sample code-
public class LoginActivity extends Activity
{
Intent i;
Button signin, signup;
String name = "", pass = "";
byte[] data;
HttpPost httppost;
StringBuffer buffer;
HttpResponse response;
HttpClient httpclient;
InputStream inputStream;
SharedPreferences app_preferences, pref;
List<NameValuePair> nameValuePairs;
EditText editTextId, editTextP;
SharedPreferences.Editor editor;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
signin = (Button) findViewById(R.id.signin);
signup = (Button) findViewById(R.id.signup);
editTextId = (EditText) findViewById(R.id.editTextId);
editTextP = (EditText) findViewById(R.id.editTextP);
app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
String Str_user = app_preferences.getString("username", "0");
String Str_pass = app_preferences.getString("password", "0");
String Str_check = app_preferences.getString("checked", "no");
if (Str_check.equals("yes"))
{
editTextId.setText(Str_user);
editTextP.setText(Str_pass);
}
signin.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
signin.setEnabled(false);
signup.setEnabled(false);
name = editTextId.getText().toString();
pass = editTextP.getText().toString();
String Str_check2 = app_preferences.getString("checked", "no");
if (Str_check2.equals("yes")) {
SharedPreferences.Editor editor = app_preferences.edit();
editor.putString("username", name);
editor.putString("password", pass);
editor.commit();
}
if (name.equals("") || pass.equals(""))
{
Toast.makeText(LoginActivity.this, "Blank Field..Please Enter", Toast.LENGTH_SHORT).show();
signin.setEnabled(true);
signup.setEnabled(true);
}
else
{
String emailPattern = "[a-zA-Z0-9._-]+#[a-z]+\\.+[a-z]+";
if(name.matches(emailPattern))
new LoginTask().execute();
signin.setEnabled(false);
signup.setEnabled(false);
}
}
});
signup.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
Move_next();
}
});
}
public void Move_to_next()
{
final Handler handle = new Handler();
Runnable delay = new Runnable() {
public void run() {
startActivity(new Intent(LoginActivity.this, SplashActivity.class));
finish();
}
};
handle.postDelayed(delay,2000);
}
public void Move_next()
{
startActivity(new Intent(LoginActivity.this, SignUpActivity.class));
finish();
}
#SuppressLint("NewApi")
private class LoginTask extends AsyncTask <Void, Void, String>
{
#SuppressLint("NewApi")
#Override
protected void onPreExecute()
{
super.onPreExecute();
// Show progress dialog here
}
#Override
protected String doInBackground(Void... arg0) {
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://website.com/yourpagename.php");
// Add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data))) {
buffer.append(new String(data, 0, len));
}
inputStream.close();
return buffer.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return "";
}
#SuppressLint("NewApi")
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// Hide progress dialog here
if (buffer.charAt(0) == 'Y')
{
Toast.makeText(LoginActivity.this, "login successfull", Toast.LENGTH_SHORT).show();
Move_to_next();
}
else
{
Toast.makeText(LoginActivity.this, "Invalid Username or password", Toast.LENGTH_SHORT).show();
signin.setEnabled(true);
signup.setEnabled(true);
}
}
}
}
I am creating sign up page for my app. I have 4 text fields in below code EditEmail, EditPass, EditRepass, EditMobile. I already made login page, now I need to make some changes in my login code to make sign up page work. But I think I made few mistakes. In login I have a check box, but in this code it is not required. I do not know how to tackle with checbox code. I want to send the above 4 fields to my remote server and check if "email id" is not used before then user get registered. How should I make the following code perfect.
public class SignUpActivity extends Activity
{
EditText editEmail, editPass, editRepass, editMobile;
Button submit,exit;
String name = "", pass = "", repass = "", mobile = "";
SharedPreferences app_preferences;
Intent i;
CheckBox check;
byte[] data;
HttpPost httppost;
HttpResponse response;
HttpClient httpclient;
StringBuffer buffer;
InputStream inputStream;
List<NameValuePair> nameValuePairs;
#Override
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.signup);
submit = (Button) findViewById(R.id.submit);
exit = (Button) findViewById(R.id.exit);
editEmail=(EditText)findViewById(R.id.editEmail);
editPass=(EditText)findViewById(R.id.editPass);
editRepass=(EditText)findViewById(R.id.editRepass);
editMobile=(EditText)findViewById(R.id.editMobile);
app_preferences = PreferenceManager.getDefaultSharedPreferences(this);
check = (CheckBox) findViewById(R.id.check);
String Str_user = app_preferences.getString("username", "0");
String Str_pass = app_preferences.getString("password", "0");
String Str_repass = app_preferences.getString("repassword", "0");
String Str_mobile = app_preferences.getString("mobile", "0");
String Str_check = app_preferences.getString("checked", "no");
if (Str_check.equals("yes")) {
editTextId.setText(Str_user);
editTextP.setText(Str_pass);
check.setChecked(true);
}
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
name = editEmail.getText().toString();
pass = editPass.getText().toString();
repass = editRepass.getText().toString();
mobile = editMobile.getText().toString();
String Str_check2 = app_preferences.getString("checked", "no");
if (Str_check2.equals("yes")) {
SharedPreferences.Editor editor = app_preferences.edit();
editor.putString("username", name);
editor.putString("password", pass);
editor.putString("repassword", repass);
editor.putString("umobile", mobile);
editor.commit();
}
if (name.equals("") || pass.equals("") || repass.equals("") || mobile.equals("") ) {
Toast.makeText(SignUpActivity.this, "Blank Field..Please Enter", Toast.LENGTH_SHORT).show();
} else {
}
}
});
exit.setOnClickListener(new View.OnClickListener ()
{
public void onClick(View v)
{
finish();
}
});
}
public void Move_to_next1()
{
startActivity(new Intent(SignUpActivity.this, SplashActivity.class));
finish();
}
#SuppressLint("NewApi")
private class LoginTask extends AsyncTask <Void, Void, String>
{
#SuppressLint("NewApi")
#Override
protected void onPreExecute()
{
super.onPreExecute();
// Show progress dialog here
}
#Override
protected String doInBackground(Void... arg0) {
try {
httpclient = new DefaultHttpClient();
httppost = new HttpPost("http://abc.com/login1.php");
// Add your data
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("UserEmail", name.trim()));
nameValuePairs.add(new BasicNameValuePair("Password", pass.trim()));
nameValuePairs.add(new BasicNameValuePair("RePassword", repass.trim()));
nameValuePairs.add(new BasicNameValuePair("Mobile", mobile.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
response = httpclient.execute(httppost);
inputStream = response.getEntity().getContent();
data = new byte[256];
buffer = new StringBuffer();
int len = 0;
while (-1 != (len = inputStream.read(data))) {
buffer.append(new String(data, 0, len));
}
inputStream.close();
return buffer.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return "";
}
#SuppressLint("NewApi")
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// Hide progress dialog here
if (buffer.charAt(0) == 'Y')
{
Toast.makeText(SignUpActivity.this, "Succesfully Registered", Toast.LENGTH_SHORT).show();
Move_to_next1();
}
else
{
Toast.makeText(SignUpActivity.this, " E-Mail Already Registered", Toast.LENGTH_SHORT).show();
}
}
}
}
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
android.os.NetworkOnMainThreadException
When I run the my android application, I got android.os.NetworkOnMainThreadException, what is the reason for that.how do I fix It.this is my code
public class Login extends Activity {
private Button btnLogin;
private EditText txtusername;
private EditText txtPassword;
public String username;
public String password;
public boolean doLogin = false;
Intent intent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.login);
btnLogin = (Button) findViewById(R.id.btnLogin);
txtusername = (EditText) findViewById(R.id.txtuserName);
txtPassword = (EditText) findViewById(R.id.txtPassword);
btnLogin.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
username = txtusername.getText().toString();
password = txtPassword.getText().toString();
if (username.equals("") || password.equals("")) {
AlertDialog alert = new AlertDialog.Builder(Login.this)
.create();
alert.setMessage("Username or Password can not be Empty");
alert.setButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
alert.setIcon(R.drawable.loginlogo);
alert.show();
}
else {
HttpAsync httpasync = new HttpAsync();
httpasync.execute(new String[] { "http://www.diskonbanget.com/bni/login/login.php" });
}
}
});
}
private class HttpAsync extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
String str = null;
try {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://www.diskonbanget.com/bni/login/login.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
2);
nameValuePairs
.add(new BasicNameValuePair("username", username));
nameValuePairs
.add(new BasicNameValuePair("password", password));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
str = inputStreamToString(response.getEntity().getContent())
.toString();
} catch (Exception e) {
return str;
}
return str;
}
#Override
protected void onPostExecute(String result) {
String str = result;
if (str.toString().equalsIgnoreCase("false")) {
AlertDialog alert = new AlertDialog.Builder(Login.this)
.create();
alert.setMessage("Please enter valid username & Password");
alert.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.setIcon(R.drawable.loginlogo);
alert.show();
}
else if (str.toString().equalsIgnoreCase("null")) {
AlertDialog alert = new AlertDialog.Builder(Login.this)
.create();
alert.setMessage("Can not Connect to the server.please make sure your internet is Switch on ");
alert.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.setIcon(R.drawable.loginlogo);
alert.show();
}
else {
intent = new Intent(Login.this, MainMenu.class);
intent.putExtra("photo", str);
intent.putExtra("username", str);
getApplicationContext().startActivity(intent);
}
}
}
private StringBuilder inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
try {
while ((line = rd.readLine()) != null) {
total.append(line);
}
return total;
} catch (Exception e) {
return null;
}
}
please someone help me.android version3.2, try to run using XOOM2 emulator
The reason is that your login method makes an http connection in the ui thread, you should do it in a separate thread or use an AsynchTask..
You can pass the context to the task, and then:
protected void onPostExecute(Void result) {
Intent showContent = new Intent(context, yourActivity.class);
context.startActivity(showContent);
}
I dont advise it though but you can use this for test. Refer to #imran khan for good practice.
Add this in your onCreate() method to bypass the checking.
if( Build.VERSION.SDK_INT >= 9){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}