I turn off my firewall, but persist the problem, com.android.volley.NetworkError
Also I implemented in the manifest, but nothing
public class MainActivity extends AppCompatActivity implements
Response.Listener<JSONObject>, Response.ErrorListener {
//declare variables
Button btnlogin;
TextView tvcreateuser;
private ViewPager screenPager;
RequestQueue rq;
JsonRequest jrq;
EditText cajaUser,cajaPwd;
Button btnConsultar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//start variables
btnlogin = (Button)findViewById(R.id.btnlogin);
tvcreateuser = (TextView)findViewById(R.id.tvcreateuser);
cajaUser = (EditText)findViewById(R.id.txtUser);
cajaPwd =(EditText)findViewById(R.id.txtPwd);
btnConsultar = (Button)findViewById(R.id.btnSesion);
rq = Volley.newRequestQueue(this);
btnConsultar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
iniciarSesion();
}
});
//functions
login();
createuser();
}
private void createuser() {
tvcreateuser.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,CreateUserActivity.class);
startActivity(intent);
}
});
}
private void login() {
btnlogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,PrincipalActivity.class);
startActivity(intent);
}
});
}
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(this, "Nada perrito"+error.toString(), Toast.LENGTH_SHORT).show();
}
#Override
public void onResponse(JSONObject response) {
Toast.makeText(this, "Se encontro el usuario", Toast.LENGTH_SHORT).show();
User usuario = new User();
JSONArray jsonArray = response.optJSONArray("datos");
JSONObject jsonObject = null;
try {
jsonObject = jsonArray.getJSONObject(0);
usuario.setUser(jsonObject.optString("user"));
usuario.setPwd(jsonObject.optString("pwd"));
usuario.setNames(jsonObject.optString("names"));
} catch (JSONException e) {
e.printStackTrace();
}
}
private void iniciarSesion(){
String url = "http://10.62.2.71/login/sesion.php?user="+cajaUser.getText().toString()+
"&pwd="+cajaPwd.getText().toString();
jrq = new JsonObjectRequest(Request.Method.GET,url,null,this,this);
rq.add(jrq);
}
}
I turn off my firewall, but persist the problem, com.android.volley.NetworkError
Add this line to AndroidManifest.xml
<manifest ....>
<uses-permission android:name="android.permission.INTERNET" />
<application>
....
</manifest>
Related
My app contained a login button and whenever that button is pressed, I want some Progress Bar to show up so that the user knows there is something happening. I've Progress Bar in XML but now i don't know how to set it in code. Please guide me where to put lines as when I press login button a Progress Bar shown up, here is my code
<ProgressBar
android:id="#+id/loading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layout_password"
android:layout_marginTop="30dp"
android:visibility="gone"/>
<Button
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="55dp"
android:text="login"
android:layout_below="#id/layout_password"
android:layout_marginTop="30dp"/>
MainActivity.java
public class MainActivity extends AppCompatActivity {
TextView textView;
EditText email,password;
Button login;
String url="http://192.168.1.5/Register/login.php" ;
AlertDialog.Builder builder;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=findViewById(R.id.register);
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,Register.class);
startActivity(intent);
}
});
email=findViewById(R.id.email);
password=findViewById(R.id.password);
login=findViewById(R.id.login);
builder=new AlertDialog.Builder(MainActivity.this);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String user_email=email.getText().toString();
final String user_password=password.getText().toString();
if (user_email.equals("")||user_password.equals("")){
builder.setTitle("Something Went Wrong...");
dispalyAlert("Enter a valid Email and Password");
}
else {
StringRequest stringRequest=new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONArray jsonArray=new JSONArray(response);
JSONObject jsonObject=jsonArray.getJSONObject(0);
String code=jsonObject.getString("code");
if (code.equals("login_failed")){
builder.setTitle("Login Error...");
dispalyAlert(jsonObject.getString("message"));
}
else {
Intent intent=new Intent(MainActivity.this,LoginSuccess.class);
Bundle bundle=new Bundle();
bundle.putString("name",jsonObject.getString("name"));
// bundle.putString("email",jsonObject.getString("email"));
intent.putExtras(bundle);
startActivity(intent);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_LONG).show();
error.printStackTrace();
}
}){
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params=new HashMap<>();
params.put("email",user_email);
params.put("password",user_password);
return params;
}
};
MySingleton.getInstance(MainActivity.this).addToRequestQueue(stringRequest);
}
}
});
}
private void dispalyAlert(String message){
builder.setMessage(message);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
email.setText("");
password.setText("");
}
});
AlertDialog alertDialog=builder.create();
alertDialog.show();
}
You can achieve this as following. you don't have to add the progressBar in xml.
public class MainActivity extends AppCompatActivity {
TextView textView;
EditText email,password;
Button login;
String url="http://192.168.1.5/Register/login.php" ;
//To show the progressBar
private ProgressDialog progress;
AlertDialog.Builder builder;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Prepare progressBar
progress = new ProgressDialog(this);
progress.setTitle("Please Wait!!");
progress.setMessage("Wait!!");
progress.setCancelable(false);
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
textView=findViewById(R.id.register);
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,Register.class);
startActivity(intent);
}
});
email=findViewById(R.id.email);
password=findViewById(R.id.password);
login=findViewById(R.id.login);
builder=new AlertDialog.Builder(MainActivity.this);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String user_email=email.getText().toString();
final String user_password=password.getText().toString();
if (user_email.equals("")||user_password.equals("")){
builder.setTitle("Something Went Wrong...");
dispalyAlert("Enter a valid Email and Password");
}
else {
//Show the progressBar
progress.show();
StringRequest stringRequest=new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
//Hide the progressBar
progress.dismiss();
try {
JSONArray jsonArray=new JSONArray(response);
JSONObject jsonObject=jsonArray.getJSONObject(0);
String code=jsonObject.getString("code");
if (code.equals("login_failed")){
builder.setTitle("Login Error...");
dispalyAlert(jsonObject.getString("message"));
}
else {
Intent intent=new Intent(MainActivity.this,LoginSuccess.class);
Bundle bundle=new Bundle();
bundle.putString("name",jsonObject.getString("name"));
// bundle.putString("email",jsonObject.getString("email"));
intent.putExtras(bundle);
startActivity(intent);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
//Hide the progressBar
progress.dismiss();
Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_LONG).show();
error.printStackTrace();
}
}){
#Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params=new HashMap<>();
params.put("email",user_email);
params.put("password",user_password);
return params;
}
};
MySingleton.getInstance(MainActivity.this).addToRequestQueue(stringRequest);
}
}
});
}
private void dispalyAlert(String message){
builder.setMessage(message);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
email.setText("");
password.setText("");
}
});
AlertDialog alertDialog=builder.create();
alertDialog.show();
}
}
You should be set progress bar visible when user click on button:
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String user_email=email.getText().toString();
final String user_password=password.getText().toString();
if (user_email.equals("")||user_password.equals("")){
builder.setTitle("Something Went Wrong...");
dispalyAlert("Enter a valid Email and Password");
}else{ //Right here
findViewById(R.id.loading).setVisible(View.VISIBLE);
You have to set visibility to gone when stop to load :
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONArray jsonArray=new JSONArray(response);
JSONObject jsonObject=jsonArray.getJSONObject(0);
String code=jsonObject.getString("code");
if (code.equals("login_failed")){
builder.setTitle("Login Error...");
dispalyAlert(jsonObject.getString("message"));
}
else {
Intent intent=new Intent(MainActivity.this,LoginSuccess.class);
Bundle bundle=new Bundle();
bundle.putString("name",jsonObject.getString("name"));
// bundle.putString("email",jsonObject.getString("email"));
intent.putExtras(bundle);
startActivity(intent);
}
} catch (JSONException e) {
e.printStackTrace();
}
findViewById(R.id.loading).setVisible(View.GONE); ////Here
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
findViewById(R.id.loading).setVisible(View.GONE); //Here
Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_LONG).show();
error.printStackTrace();
}
This is My LoginActivity.java
public class LoginActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener,
View.OnClickListener {
#BindView(R.id.login_facebook)
Button loginFacebookBtn;
#BindView(R.id.privacy_policy)
TextView privacyPolicy;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
Backendless.setUrl(AppConstant.SERVER_URL);
Backendless.initApp(this, AppConstant.APPLICATION_ID, AppConstant.API_KEY);
String userToken = UserTokenStorageFactory.instance().getStorage().get();
if (userToken != null && !userToken.equals("")) {
Backendless.UserService.isValidLogin(new DefaultCallback<Boolean>(this) {
#Override
public void handleResponse(Boolean isValidLogin) {
if (isValidLogin && Backendless.UserService.CurrentUser() == null) {
String currentUserId = Backendless.UserService.loggedInUser();
if (!currentUserId.equals("")) {
Backendless.UserService.findById(currentUserId, new DefaultCallback<BackendlessUser>(LoginActivity.this, "Logging in...") {
#Override
public void handleResponse(BackendlessUser currentUser) {
super.handleResponse(currentUser);
Backendless.UserService.setCurrentUser(currentUser);
ActivityHelper.start(LoginActivity.this, MainActivity.class);
finish();
}
});
}
}
super.handleResponse(isValidLogin);
}
});
}
loginWithFacebook();
privacyPolicy.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(LoginActivity.this, PrivacyPolicy.class));
}
});
registerDevice();
}
private void registerDevice() {
Backendless.Messaging.registerDevice(AppConstant.GCM_SENDER_ID, AppConstant.MESSAGING_CHANNEL, registerCallback());
}
private DefaultCallback<Void> registerCallback() {
return new DefaultCallback<Void>(this) {
#Override
public void handleResponse(Void response) {
super.handleResponse(response);
}
#Override
public void handleFault(BackendlessFault fault) {
super.handleFault(fault);
}
};
}
private void loginWithFacebook() {
loginFacebookBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onLoginWithFacebookButtonClicked();
}
});
}
private void onLoginWithFacebookButtonClicked() {
Map<String, String> facebookFieldsMapping = new HashMap<>();
facebookFieldsMapping.put("name", "name");
facebookFieldsMapping.put("email", "email");
List<String> facebookPermissions = new ArrayList<>();
facebookPermissions.add("email");
Backendless.UserService.loginWithFacebook(LoginActivity.this, null, facebookFieldsMapping, facebookPermissions, new SocialCallback<BackendlessUser>(LoginActivity.this) {
#Override
public void handleResponse(BackendlessUser response) {
ActivityHelper.start(LoginActivity.this, MainActivity.class);
finish();
}
#Override
public void handleFault(BackendlessFault fault) {
super.handleFault(fault);
Toasty.info(LoginActivity.this, "Try again, please ..", Toast.LENGTH_LONG).show();
}
}, true);
}
#Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
System.exit(0);
}
#Override
public void onClick(View view) {
}
#Override
public void onConnectionFailed(#NonNull ConnectionResult connectionResult) {
}}
This is my facebook developers account settings
facebook screenshot 1
facebook screenshot 2
facebook screenshot 3
My Code is successfully running in android studio without any error.But when i run the application i am getting this error.
Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.
error screenshot
I have created my LoginActivity.java bye taking this as a reference
https://backendless.com/documentation/users/android/index.html?users_facebook_login.htm
searched a lot in the web But Didn't get any relevant solution Can anybody help??
it looks like you are missing App Domain in your facebook settings (Settings > Basic > App Domains).
Try to add as your domain
api.backendless.com
If this is not working try to take a look at this https://backendless.com/documentation/manage/mgmt_social_settings.htm
I have created an app in android studio and I have a java file name Login.java. In which I had checked a particular mpin entered by user exists in firebase real time database or not.
Now I want that in else loop mpin doesn't exists then it should remain on Login activity.
How can this be done?
public class Login extends AppCompatActivity {
String enteredmPINString;
EditText enteredmPin;
DatabaseReference rootref;
String contactfromPhoneLogin;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Button mLoginSubmit;
mLoginSubmit = (Button) findViewById(R.id.loginSubmit);
Bundle b = getIntent().getExtras();
if(b!=null){
contactfromPhoneLogin = b.getString("contacttoLogin");
Log.d("abcd",contactfromPhoneLogin);
}
rootref= FirebaseDatabase.getInstance().getReference("Employees").child(contactfromPhoneLogin).child("empmpin");
Log.d("abcd","Database reference reached");
// enteredmPin = (EditText) findViewById(R.id.editTextmPIN);
// enteredmPINString = enteredmPin.getText().toString();
View.OnClickListener submitListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
enteredmPin = (EditText) findViewById(R.id.editTextmPIN);
enteredmPINString = enteredmPin.getText().toString();
Log.d("abcd",enteredmPINString);
final Intent loginIntent = new Intent(Login.this,NavigationDrawer.class);
loginIntent.putExtra ("mPINtoNavigation",enteredmPINString);
Log.d("abcd","Login.java sending"+enteredmPINString);
startActivity(loginIntent);
rootref.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d("abcd","onDatachange reached");
Log.d("abcd",enteredmPINString);
if(dataSnapshot.child(enteredmPINString).exists()){
Log.d("abcd","mpin exists");
Intent loginIntent = new Intent(Login.this,NavigationDrawer.class);
loginIntent.putExtra ("mPINtoNavigation",enteredmPINString);
Log.d("abcd","Login.java sending"+enteredmPINString);
startActivity(loginIntent);
}
else{
Toast.makeText(Login.this,"Invalid mPIN!",Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
};
mLoginSubmit.setOnClickListener(submitListener);
}
public void erp_site(View view){
Intent erpIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://web.nbccho.com/erp/"));
startActivity(erpIntent);
}
public void nbcc_site(View view){
Intent nbcc_siteIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.nbccindia.com/nbccindia/index.jsp"));
startActivity(nbcc_siteIntent);
}
}
remove the intent in onClick();
View.OnClickListener submitListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
enteredmPin = (EditText) findViewById(R.id.editTextmPIN);
enteredmPINString = enteredmPin.getText().toString();
Log.d("abcd",enteredmPINString);
Log.d("abcd","Login.java sending"+enteredmPINString);
I have a problem with this, the editText in the log is sending data but the String is null and the object is null
this is my code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_group_chat);
mSendMessage = (ImageButton) findViewById(R.id.imageButtongrupalSend);
mGetText = (EditText) findViewById(R.id.textoDeEdicionChat);
mChat = new GroupalChat();
mPost = (Post) getIntent().getParcelableExtra("grupal");
final String lel = mGetText.getText().toString();
mChat.setMsj(lel);
mChat.setTiempoMensaje(System.currentTimeMillis());
mSendMessage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FirebaseUtils.getGrupalChatRef(mPost.getId()).push().setValue(mChat).addOnSuccessListener(GroupChatActivity.this, new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
Log.d("lol", lel);
Log.d("jeje", mChat.getMsj());
}
});
}
});
}
the log is not receiving anything
and the string is not receiving anything
Move this final String lel = mGetText.getText().toString(); inside the click listener and it will work.
mSendMessage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String lel = mGetText.getText().toString();
mChat = new GroupalChat();
mChat.setMsj(lel);
mChat.setTiempoMensaje(System.currentTimeMillis());
Log.d("lol", lel);
Log.d("jeje", mChat.getMsj());
FirebaseUtils.getGrupalChatRef(mPost.getId()).push().setValue(mChat).addOnSuccessListener(GroupChatActivity.this, new OnSuccessListener<Void>() {
#Override
public void onSuccess(Void aVoid) {
Log.d("lol", "Success");
}
});
}
});
Your version doesn't work because lel has already been bound to some value before the click listener has even been created.
am developing an app where user can login by clicking login button with facebook.For facebook login i added library etc for facebook.
i have tried everything to get keyhash but still i am unable to get key hash for development of facebook login for my app.
i have added this C:\Program Files\Java\jdk1.8.0_112\jre\bin and
this C:\OpenSSL\bin .
i tried with the method given in different sites but still some problem ..kindly help
here is my Login.java
public class Login extends AppCompatActivity {
private String eml;
private String pswrd;
private ProgressDialog pDialog;
String status="";
Button login;
// private int serverResponseCode = 0;
TextView tac1;
EditText email,pass;
private static String url_create_book = "http://cloud....com/broccoli/login.php";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
email=(EditText)findViewById(R.id.email);
pass=(EditText)findViewById(R.id.password);
tac1 = (TextView) findViewById(R.id.cAcc);
tac1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Login.this, RegistrationForm.class));
}
});
login=(Button)findViewById(R.id.lbtn);
login.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
pDialog = new ProgressDialog(Login.this);
pDialog.setMessage("Please wait..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
eml = email.getText().toString();
pswrd = pass.getText().toString();
// new CreateNewProduct().execute();
StringRequest stringRequest = new StringRequest(Request.Method.POST, url_create_book,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
pDialog.dismiss();
if (response.trim().equals("success")) {
Toast.makeText(Login.this,"Login Success",Toast.LENGTH_SHORT).show();
//your intent code here
} else {
Toast.makeText(Login.this,"username/password incorrect",Toast.LENGTH_SHORT).show();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
pDialog.dismiss();
Toast.makeText(Login.this, error.toString(), Toast.LENGTH_LONG).show();
}
})
{
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("email", eml);
params.put("password",pswrd);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(Login.this);
requestQueue.add(stringRequest);
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}