ive been trying for a long time and i cant manage to find a solution
in the User class in parse, I added a new column and called it bio, im trying to retrieve that so i can set it inside the user's profile TextView, inside of android studio ofc
Intent intent = getIntent();
String usersUsername = intent.getStringExtra("username");
ParseQuery<ParseUser> bioQuery = ParseQuery.getQuery("User");
bioQuery.whereEqualTo("username", usersUsername);
bioQuery.getInBackground("bio", new GetCallback<ParseUser>() {
#Override
public void done(ParseUser object, ParseException e) {
if (e == null){
Log.i("info", "happy");
} else {
Log.i("info", "sad");
}
}
});
im getting the right username with the intent, im getting it from a listview that hold the users usernames
i always get "sad", i tried multiple other ways and regarding those other ways it
kept on telling me that there were no queries that match
please assist me, thank you.
Try with findInBackground. It should be something like:
Intent intent = getIntent();
String usersUsername = intent.getStringExtra("username");
ParseQuery<ParseUser> bioQuery = ParseQuery.getQuery(ParseUser);
bioQuery.whereEqualTo("username", usersUsername);
bioQuery.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
if (e == null){
Log.i("info", "happy");
} else {
Log.i("info", "sad");
}
}
});
You also need to make sure that you have access to the user. If it is not the current logged in user, you probably do not have access.
for anyone looking for an answer to a question like mine, I managed to get a solution, which at second glance should've been obvious
I took Davi's advice and added to it what I needed
Intent intent = getIntent();
String usersUsername = intent.getStringExtra("username");
ParseQuery<ParseUser> bioQuery = ParseUser.getQuery();
bioQuery.whereEqualTo("username", usersUsername);
bioQuery.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
if (e == null){
Log.i("info", "happy");
for(ParseUser user : objects){
Log.i("info", (String) user.get("bio"));
bio = (String) user.get("bio");
}
fullBioTextView.setText(bio);
} else {
Log.i("info", "sad");
}
}
});
Related
This is probably a very basic question but I couldn't find the answer.
I need to pass data from RecyclerView but when I check it on related activity, data is null.
mvHolder.barcode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent s = new Intent(context, SummaryActivity.class);
s.putExtra("SUMMARY",sp.getDATA().get(i).getId_summary()); // data is not null
context.startActivity(s);
}
});
and this is how I try to achieve it :
Bundle extras = getIntent().getExtras();
if (extras != null) {
strBarcode = extras.getString("SUMMARY");
// and get whatever type user account id is
}
but when I debug it, it turns out that strBarcode is null. I don't know what the problem is, I guess my code should be works either. Please help me
Intent data = getIntent();
if (data != null) {
strBarcode = data.getStringExtra("SUMMARY");
// and get whatever type user account id is
}
Intent data = getIntent();
if (data != null) {
int strBarcode = data.getIntExtra("SUMMARY");
}
Please try this
Check if getIntent().hasExtra("SUMMARY") returns true.
If it does, make sure that sp.getDATA().get(i).getId_summary() returns a String.
The extra might be there, but you try to get as String, and it might
have different type.
I am working on an android app whose main purpose is to update the working location of the employees by admin. Now when I want to change/update the location of an employee from my recycler view(list of employees connected with my UserManagerAdapter), I have to pass the user name of that employee to the place picker intent so that when the admin pick the desired location, the database of that user will be changed accordingly.
My Steps(2 Steps)
I have passed the username to the place picker intent as bundle.
My UserManagerAdapter
holder.locationTv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
launchPicker(data.get(position).getUserName());
}
});
private void launchPicker(String userName) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Bundle bundle = new Bundle();
bundle.putString(USERNAME,userName);
try {
fragment.startActivityForResult(builder.build(fragment.getActivity()),PLACE_PICKER_REQUEST,bundle);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
I received the location request inside of a fragment and update the location of that particular user
My ManageUserFragment
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PLACE_PICKER_REQUEST){
if(resultCode == RESULT_OK){
Place place = PlacePicker.getPlace(getContext(),data);
address = place.getAddress().toString();
String latLng = place.getLatLng().toString();
latLang = latLng;
//update user's decided location
Bundle bundle = data.getExtras();
String userName = bundle.getString(USERNAME);// it returns null, Why?
updateLocation(latLang,userName);
Toast.makeText(getContext(), latLng, Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), getContext().getText(R.string.locationError), Toast.LENGTH_SHORT).show();
}
}
}
My constant is
public static final String USERNAME="Username";
Now,
My problem is
Why bundle.getString(USERNAME) always return null?
How to pass data to place picker intent so that we can receive it in
onActivityResult ?
After replicating your case and researching for a little bit, I found out that the third parameter in startActivityForResult() is not used to pass a bundle of values to the onActivityResult, it's used to pass options to Android itself, you can find those here. So if you want to pass any data you have to use an intent with putExtra("USERNAME", username), and you can retrieve it with getStringExtra("USERNAME"). It's explained in this answer as well.
I am working on a login function with facebook for my android app.
I have almost everything done but i can't get all the fields.
Im getting only something in fullname and the fbid.
First name, Gender, Profile picture returns nothing.
GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject fbUser,
GraphResponse response) {
final ParseUser parseUser = ParseUser.getCurrentUser();
try{
parseUser.fetchIfNeeded();
}catch (Exception e){}
if (fbUser != null && parseUser != null
&& fbUser.optString("name").length() > 0) {
Log.d("fb","Json--"+fbUser);
parseUser.put(USER_OBJECT_NAME_FIELD, fbUser.optString("first_name"));
parseUser.put("fullname",fbUser.optString("name"));
try{
String mm= fbUser.getString("email");
parseUser.setEmail(mm);
}catch (Exception e){//e.printStackTrace();
}
try{
String mm= fbUser.getString("gender");
if(mm.equals("male"))
{
For profile pic i'm using this:
try {
final String id = fbUser.getString("id");
parseUser.put("fbId", id);
//Your code goes here
String ur = "https://graph.facebook.com/" + id + "/picture?width=640&height=640";
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(getActivity().getApplicationContext()));
imageLoader.loadImage(ur, new SimpleImageLoadingListener() {
#Override
public void onLoadingComplete(String imageUri, View view, Bitmap bmImg) {
// Do whatever you want with Bitmap
if(bmImg!=null) {
bmImg=Bitmap.createScaledBitmap(bmImg,640,640,false);
ParseFile dL = new ParseFile("dpLarge.jpg", bmImg.toString().getBytes());
Bitmap smal = Bitmap.createScaledBitmap(bmImg, 120, 120, false);
ParseFile ds = new ParseFile("dpSmall.jpg", smal.toString().getBytes());
parseUser.put("dpLarge", dL);
parseUser.put("dpSmall", ds);
}
Permissions:
facebookLoginButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
loadingStart(false); // Facebook login pop-up already has a spinner
if (config.isFacebookLoginNeedPublishPermissions()) {
ParseFacebookUtils.logInWithPublishPermissionsInBackground(getActivity(),
config.getFacebookLoginPermissions(), facebookLoginCallbackV4);
} else {
ParseFacebookUtils.logInWithReadPermissionsInBackground(getActivity(),
config.getFacebookLoginPermissions(), facebookLoginCallbackV4);
}
}
});
}
Can't figure out what im doing wrong.
I haven't already used facebook sdk, but according to your problem with a profile picture, did you tried solutions from these posts:
How to get facebook profile picture of user in facebook SDK 3.0 Android
How to get facebook profile picture of user in facebook SDK Android
Try also to use some logs for example to check if String ur appears correctly.
so I store some basic data using parse in one activity, but how do I retrieve that data from parse(query it) in another activity? Can someone give me a clean cut example?
So in my main activity I have
public String max = "max";
Parse.enableLocalDatastore(this);
private ParseObject rightCardsStore = new ParseObject("RightCardsStore");
rightCardsStore.put("max",max);
rightCardsStore.saveInBackground();
Now, in another activity, "Folder.java" I want to query/retrieve that data and use that string.
As hitch.united said, you need to get the ID by doing a saveInBackground and send it to the other activity:
rightCardsStore.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Intent intent = new Intent(YourCurrentActivity.this, YourNewActivity.class);
intent.putExtra("parseObjectId", rightCardsStore.getObjectId());
YourCurrentActivity.this.startActivity(intent);
}
}
});
Then you can retrieve the data in your other activity, and query parse:
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String id = bundle.getString("parseObjectId");
ParseQuery<ParseObject> query = ParseQuery.getQuery("RightCardsStore");
query.getInBackground(id, new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// object is the RightCardsStore you just saved
String max = object.getString("max");
}
}
}
}
If you just need to use max as a readonly value you can simplify the process by replacing (in the first activity)
intent.putExtra("parseObjectId", rightCardsStore.getObjectId());
by
intent.putExtra("max", max);
and replacing the second activity by:
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String max = bundle.getString("max");
}
After the saveInBackground get the ID of the object and pass it with an intent to the new activity. You can then requery with that ID to retrieve the object.
I've tested my android app successfully using Paypal Sandbox environment. I am about to release my app, so want to change the paypal configuration to 'PRODUCTION'
To do this, I've changed the following for production:
private static final String CONFIG_ENVIRONMENT = PaymentActivity.ENVIRONMENT_PRODUCTION;
private static final String CONFIG_CLIENT_ID = "my client id for production";
private static final String CONFIG_RECEIVER_EMAIL = "live-id#gmail.com";
Now when I try to make a payment using my another paypal account, I am getting error:
Login Failed
System error. Please try again later.
Same thing happens using the emulator with production settings.
My question is do I have to make any other changes to move from sandbox to production env?
Thanks
UPDATE 1
All the above settings are for the 'production' environment.
Using direct payment
I've noticed problems using paypal from my app when I name the String before onCreate so what I did was..
//When you want to initiate payment...
public void onBuyPressed(View pressed) {
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(valuez), "USD", iu);
PaymentActivity.ENVIRONMENT_LIVE);//etc
I dont know if "PRODUCTION" or "LIVE" makes a difference but give it a try.
I'm going to add more hope this helps this is what i did
get rid of all those paypal strings before onCreate and just when they get ready to pay have textbox with onClick is onBuyPressed...
public void onBuyPressed(View pressed) {
TextView inptP =(TextView)findViewById(R.id.WHATHEYAREBUYING);
String iu =inptP.getText().toString();
TextView inptt =(TextView)findViewById(R.id.WHATITCOST);
String it =inptt.getText().toString();
try{
double valuez =Double.parseDouble(it);
if(valuez> 0)
{
PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal(valuez), "USD", iu);
Intent intent = new Intent(this, PaymentActivity.class);
TextView id =(TextView)findViewById(R.id.MYPAYPALID);
String uname = id.getText().toString();
TextView iz =(TextView)findViewById(R.id.MYPAYPALEMAIL);
String insane = iz.getText().toString();
TextView name =(TextView)findViewById(R.id.MYCUSTOMERSNAME);
String custname = name.getText().toString();
Time now = new Time();
now.setToNow();
// comment this line out for live or set to PaymentActivity.ENVIRONMENT_SANDBOX for sandbox
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_LIVE);
// it's important to repeat the clientId here so that the SDK has it if Android restarts your
// app midway through the payment UI flow.
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, uname);
// Provide a payerId that uniquely identifies a user within the scope of your system,
// such as an email address or user ID.
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, custname);
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, insane);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);
startActivityForResult(intent, 0);
}
else{
Toast.makeText(getApplicationContext(), "You haven't entered anything.",
Toast.LENGTH_LONG).show();
}} catch (NumberFormatException e) {
}}
#Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
//THINGS YOU WANT IT TO WHEN THE PAYMENT IS FINISHED GO BETWEEN HERE
//AND HERE
if (confirm != null) {
try {
Log.i("paymentExample", confirm.toJSONObject().toString(4));
// TODO: send 'confirm' to your server for verification.
// see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.
} catch (JSONException e) {
Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
}
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("paymentExample", "The user canceled.");
}
else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
}}
No need to put PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT for live.
This is my code which is working fine.
Declare these constants is class scope. NOTE: There are two client ids in page of your application in developer Paypal. One in "Test credentials" and The other under "Live credentials" that you should click on "show" link in order to see it. Select client id of "Live credentials" if you want to release your application.
private static final String PAYPAL_CLIENT_ID = "YOUR-CLIENT-IT";
private static final String PAYPAL_RECEIVER_EMAIL = "YOUR-EMAIL";
Then define service in onCreate():
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// start Paypal service
Intent intent = new Intent(this, PayPalService.class);
// live: don't put any environment extra
// sandbox: use PaymentActivity.ENVIRONMENT_SANDBOX
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_PRODUCTION);
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, PAYPAL_CLIENT_ID);
startService(intent);
}
When user hit a button following method will run:
private void openDonateBtnPressed(BigDecimal donation) {
PayPalPayment payment = new PayPalPayment(donation, "USD", "Donation");
Intent intent = new Intent(this, PaymentActivity.class);
// comment this line out for live or set to PaymentActivity.ENVIRONMENT_SANDBOX for sandbox
intent.putExtra(PaymentActivity.EXTRA_PAYPAL_ENVIRONMENT, PaymentActivity.ENVIRONMENT_PRODUCTION);
// it's important to repeat the clientId here so that the SDK has it if Android restarts your
// app midway through the payment UI flow.
intent.putExtra(PaymentActivity.EXTRA_CLIENT_ID, PAYPAL_CLIENT_ID);
// Provide a payerId that uniquely identifies a user within the scope of your system,
// such as an email address or user ID.
intent.putExtra(PaymentActivity.EXTRA_PAYER_ID, "<someuser#somedomain.com>");
intent.putExtra(PaymentActivity.EXTRA_RECEIVER_EMAIL, PAYPAL_RECEIVER_EMAIL);
intent.putExtra(PaymentActivity.EXTRA_PAYMENT, payment);
startActivityForResult(intent, 0);
}
and this is onActivityResult():
#Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Toast.makeText(RateTheAppActivity.this, R.string.rate_donation_received, Toast.LENGTH_LONG).show();
Log.d(TAG, confirm.toJSONObject().toString(4));
} catch (JSONException e) {
Log.e(TAG, "an extremely unlikely failure occurred: ", e);
}
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
Log.d(TAG, "The user canceled.");
}
else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
Log.e(TAG, "An invalid payment was submitted. Please see the docs.");
}
}