Parse.com parseuser isnt saved on server when calling .save() android - android

Im trying to update the current user in the remote User table using save(); but the user is saved only in the local object. what im doing:
ArrayList<String> usedCoupons = new ArrayList<String>();
usedCoupons.add(couponName);
if (currentUser.getList("used_coupons") != null) {
currentUser.getList("used_coupons").addAll(usedCoupons);
} else {
currentUser.put("used_coupons", usedCoupons);
}
try {
currentUser.save();
} catch (ParseException e) {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
} else {
Toast.makeText(MainActivity.this, "קוד שגוי, אנא נסה שנית", Toast.LENGTH_SHORT).show();
}
This function always works and i can see that the coupons are being saved locally, but when i look in the parse core panel, the object is not being updated. Any idea on how can i force the parse user to sync remotely?

You need to change:
currentUser.save();
to this..
currentUser.saveInBackground();

Related

Update and retrieve chat history in smack with openfire -Android

I am making a chat application with smack library and openfire as a server but everytime i exit the chat conversation activity between two users and come back, the whole chat gets erased. I have already enabled archive settings to store one to one messages in the server but i do not know how to implement it in the app.
I want to show chats history in recyclerview by the sender and the receiver in the recyclerview.
currently i have implemented this function which caused error
private void setChatHistory(String entityBareId) {
EntityBareJid jid = null;
try {
jid = JidCreate.entityBareFrom(entityBareId);
} catch (XmppStringprepException e) {
e.printStackTrace();
}
MamManager manager = MamManager.getInstanceFor(mConnection);
MamManager.MamQueryResult r = null;
try {
try {
r = manager.mostRecentPage(jid, 10);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotLoggedInException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
}
if (r.forwardedMessages.size() >= 1) //printing first of them
{
Message message = (Message) r.forwardedMessages.get(0).getForwardedStanza();
Log.i("mam", "message received" + message.getBody());
MessagesData data = new MessagesData("send",message.getBody());
mMessagesData.add(data);
mAdapter = new ConversationAdapter(mMessagesData);
recyclerView.setAdapter(mAdapter);
}
}
Error was
Attempt to read from field 'java.util.List org.jivesoftware.smackx.mam.MamManager$MamQueryResult.forwardedMessages' on a null object reference
At r.forwardedmessages.size()>=1.
Thanks in advance
If you want to keep history of conversation, you must save them in database. MAM just for fetching old conversation from server like when you uninstall or logout the app and decide to reinstall and get old messages.
For getting messages from server be sure you already enabled it, then forwarded messages shouldnt be null. here is a guide to enable it.

Stripe payment gateway in android

I am integrating Stripe in my android application.
I have found two issues and I am stuck.
First (and major) issue is -
I have got token key from the card information. But when I tried to make my first charge, it shows error in following line.
Stripe.apiKey = "sk_test_0000000000000";
I have googled also but couldn't find any solution.
Creating Stripe Customer - cannot resolve symbol apiKey
I have even seen this kind of question too. But I failed to understand its solution.
Following is my code for making charge:
final String publishableApiKey = BuildConfig.DEBUG ?
"pk_test_000000000000000000" :
//"sk_test_00000000000000000000000" :
getString(R.string.com_stripe_publishable_key);
final TextView cardNumberField = (TextView) findViewById(R.id.cardNumber);
final TextView monthField = (TextView) findViewById(R.id.month);
final TextView yearField = (TextView) findViewById(R.id.year);
TextView cvcField = (TextView) findViewById(R.id.cvc);
Card card = new Card(cardNumberField.getText().toString(),
Integer.valueOf(monthField.getText().toString()),
Integer.valueOf(yearField.getText().toString()),
cvcField.getText().toString());
Stripe stripe = new Stripe();
stripe.createToken(card, publishableApiKey, new TokenCallback() {
public void onSuccess(Token token) {
// TODO: Send Token information to your backend to initiate a charge
Toast.makeText(
getApplicationContext(),
"Charge Token created: " + token.getId(),
Toast.LENGTH_LONG).show();
/*make a charge starts*/
// Set your secret key: remember to change this to your live secret key in production
// Create the charge on Stripe's servers - this will charge the user's card
Stripe.apiKey = "sk_test_0000000000000000000000";
try {
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 100); // amount in cents, again
chargeParams.put("currency", "usd");
chargeParams.put("source", token.getId());
chargeParams.put("description", "Example charge");
Charge charge = Charge.create(chargeParams);
System.out.println("Charge Log :" + charge);
} catch (CardException e) {
// The card has been declined
} catch (APIException e) {
e.printStackTrace();
} catch (AuthenticationException e) {
e.printStackTrace();
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (APIConnectionException e) {
e.printStackTrace();
}
/*charge ends*/
}
I have tried these code from different examples. I followed Stripe doc too.
But I got this error:
com.stripe.exception.AuthenticationException: No API key provided. (HINT: set your API key using 'Stripe.apiKey = '.
Second Issue is - about validation.
If I am entering my own card details, and if I write wrong cvv number. It still generates token key.
I have already implemented validation of fields using Stripe's official doc. I don't know how to validate it with real time data.
Solution for the First Issue:
com.stripe.Stripe.apiKey = "sk_test_xxxxxxxxxxxxxxxxxxx";
try {
final Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 500); // amount in cents, again
chargeParams.put("currency", "usd");
chargeParams.put("source", token.getId());
chargeParams.put("description", "Example charge");
new Thread(new Runnable() {
#Override
public void run() {
Charge charge = null;
try {
charge = Charge.create(chargeParams);
} catch (AuthenticationException e) {
e.printStackTrace();
} catch (InvalidRequestException e) {
e.printStackTrace();
} catch (APIConnectionException e) {
e.printStackTrace();
} catch (CardException e) {
e.printStackTrace();
} catch (APIException e) {
e.printStackTrace();
}
System.out.println("Charge Log :" + charge);
}
}).start();
} catch (Exception e) {
e.printStackTrace();
}
Stripe's Android bindings only let you tokenize card information. Once the token has been created, it must be sent to an external server where you can use it in API requests.
You cannot use the token directly from the app as the app must never have access to your secret key, where it could easily be extracted by an attacker who would then have access to your account.
Re. your second question, the card isn't validated with the bank when the token is created (there are still some basic sanity checks, such as checking the number of digits, the fact that the expiry date is in the future, etc.). It is only when you use the token in a server-side API request that the card will be checked with the bank.

Search for user on openfire server

I am working on a chat app. I Need to search for a user registered on the server.I am using following code to achieve this
UserSearchManager search = new UserSearchManager(conn.getInstance());
Form searchForm;
try {
searchForm = search.getSearchForm("search."+conn.getInstance().getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search","anurag");
ReportedData data = search.getSearchResults(answerForm,"search."+conn.getInstance().getServiceName());
if(data.getRows() != null)
{
//Toast.makeText(this,"Username Exists",Toast.LENGTH_SHORT).show();
Log.v("user","exits");
return true;
}
/*else
{
Toast.makeText(this,"Username Available",Toast.LENGTH_SHORT).show();
}*/
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.v("Exceptio occured",""+e.getMessage());
}
return false;
Howerver I am getting Sevice-unavailable(503) exception on this line
searchForm = search.getSearchForm("search."+conn.getInstance().getServiceName());
I have also included the following code
provider_manager.addIQProvider("query", "jabber:iq:search", new UserSearch.Provider());
Do i need some configuration settings on the server e.g plugins etc or anything else??
Thanks in advance.
added search.jar plugin on the server and everything turned well...

Android: How to check condition with async task return value

I am doing some processing in async task to check some values on server if the value present server php script returns true otherwise false.
everything is working fine, but whenever i am trying to check condition with the http response string the condition never gets checked..
partial code:
CheckDevice cd = new CheckDevice();
String chk[] = new String[1];
chk[0] = di.imei;
try {
cd.execute(chk).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
cd.getFinalResult(); //This returns string "true" (working outside if);
if(cd.getFinalResult == "true"){
//This loop never executes... why?
regButton.setEnabled(false);
regButton.setText("Device Already Registered");
Toast.makeText(getApplicationContext(), cd.getFinalResult(), Toast.LENGTH_LONG).show();
}
What is the problem? someone please tell...
Do,
cd.getFinalResult().equals("true") //OR
cd.getFinalResult().equalsIgnoreCase("true")
as you cannot compare strings using ( == ).
Check this for details.

Window Azure Mobile Service select Query issue. how to make query on same column of multiple value instead only single?

I am working on android to access window azure database..
My qtn is How to make an query to access data based on single column but multiple values.?
Here is my code :
try {
mClient = new MobileServiceClient(Constant.AZURE_URL, Constant.AZURE_API_KEY, getApplicationContext());
mUsersTable = mClient.getTable(Users.class);
MobileServiceTable<Users> table = mClient.getTable(Constant.TABLE_USERS, Users.class);
table.where().field("id").eq(11)
.execute(new TableQueryCallback<Users>() {
#Override
public void onCompleted(List<Users> result, int count,
Exception exception, ServiceFilterResponse response) {
if (exception != null) {
Log.d("Exception at complete::",""+exception.getCause().getMessage());
} else {
StringBuffer sb = new StringBuffer();
for (Users users_obj : result) {
System.out.println("NAMESS::::"+users_obj.getFirstName());
// userID_arr.add(users_obj.getFirstName());
}
//System.out.println("User Array"+userID_arr);
}
}
});
} catch (MalformedURLException e) {
e.printStackTrace();
Log.e("Error Mobile Service Authentication", "There was an error creating the Mobile Service. Verify the URL");
}
catch (Exception e) {
e.printStackTrace();
}
There for I am able to get complete row on the basis of single parameter in table.where().feilds.eq(11)................... so instead 11 i want to add dynamic values on .eq() ....what is approach in Android auzre to get values on multiple id request ?

Categories

Resources