I'm building a parse app and I want the user to be able to set the range in which they receive notifications from other users in. I know you can choose how far you want to send the notification with something like this
// Find users near a given location
ParseQuery userQuery = ParseUser.getQuery();
userQuery.whereWithinMiles("location", stadiumLocation, 1.0)
// Find devices associated with these users
ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", userQuery);
// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery); // Set our Installation query
push.setMessage("Free hotdogs at the Parse concession stand!");
push.sendInBackground();
But if the user receiving these notifications has their receiving range set as .5 miles or something like that I dont wan't them to receive it. Is there anyway to make this happen?
Ex: User A has a radius set to 1 mile and user B sends the message to everyone within 2 miles and User A is 1.5 miles away from User B so I don't want him to receive it.
Ex: User A has a radius set to 1 mile and user B sends message to everyone within 2 miles and User A is .5 miles away from User B he will receive that message and notification.
The second example is easy to implement its the first one that I'm not sure how to do.
Your code is working, but you need to make "SignUp" and "Login" on each device and put location to each loggined user
I do it like that but it is not properly, but working:
add it to your MyApplication.class extands Application :
Parse.enableLocalDatastore(this);
Parse.initialize(this, "TWRSFDFayfTlDsiiELyX37crtgezMs0DeQ5IXTdx", "ukuYgUJhhVybV4MtmlkKqtbkj2drEWjl5RJgpqYl");
ParseInstallation.getCurrentInstallation().saveInBackground();
// Also in this method, specify a default Activity to handle push notifications
PushService.setDefaultPushCallback(this, MainActivity.class);
String android_id = Secure.getString(getApplicationContext().getContentResolver(),Secure.ANDROID_ID);
Log.e("LOG","android id >>" + android_id);
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("UniqueId",android_id);
installation.saveInBackground();
String installationID = installation.getInstallationId();
ParseUser.logInInBackground(installationID, installationID, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Log.e(tag, "Logigned 1");
addCurrentLocation();
} else {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
String installationID = installation.getInstallationId();
user = new ParseUser();
user.setUsername(installationID);
user.setPassword(installationID);
user.setEmail(installationID+"#example.com");
// other fields can be set just like with ParseObject
// user.put("phone", "650-253-0000");
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
Log.e(tag, "signUp 1");
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
String installationID = installation.getInstallationId();
ParseUser.logInInBackground(installationID, installationID, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Log.e(tag, "Logigned 2");
addCurrentLocation();
} else {
Log.e(tag, "CANT LOGIN");
}
}
});
} else {
Log.e(tag, "signUp error 2");
}
}
});
}
}
});
after first run of app each device will be logigned with username= installationID and password = installationID you will see it on Core->Data->User Doasboard on website
after logining you need to set to each user his location simply method addCurrentLocation();
void addCurrentLocation(){
ParseGeoPoint point = new ParseGeoPoint(12, 12);
ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation();;
parseInstallation.put("user",
ParseUser.getCurrentUser());
ParseUser u= ParseUser.getCurrentUser() ;
u.put("location", point);
u.put("application", getString(R.string.app_name));
ParseGeoPoint userlocation = u.getParseGeoPoint("location");
Log.e(tag ,
"user current location: "
+userlocation.getLatitude()
+" : "+
userlocation.getLongitude());
u.saveInBackground();
}
and then post your push notification :
// Find users near a given location
ParseQuery userQuery = ParseUser.getQuery();
ParseGeoPoint stadiumLocation = new ParseGeoPoint(12.1,12.1);
userQuery.whereWithinMiles("location", stadiumLocation , 1.0);
// Find devices associated with these users
ParseQuery pushQuery = ParseInstallation.getQuery();
pushQuery.whereMatchesQuery("user", userQuery);
// Send push notification to query
ParsePush push = new ParsePush();
push.setQuery(pushQuery);
push.setMessage("Only users near 12,12 will recieve this push notification");
push.sendInBackground();
Related
I'm new with zoom integration.
I wants user login and create meeting in their account. I've done login user part using loginWithZoom method but now wants to create meeting for that auth token needed.
How can I get token when user login in zoom without OAuth?
I've found but not getting much idea. I tried with JWT token it works with
https://api.zoom.us/v2/users/me/meetings api. I gave Authorization token and content-type in
headers. it gives me all meetings of that specific user. but problem to get different authorization token for different users. I don't have idea is it possible or not.
Suggest if anyone knows
Code I've used for Login:
public void initializeSdk(Context context) {
ZoomSDK sdk = ZoomSDK.getInstance();
// TODO: Do not use hard-coded values for your key/secret in your app in production!
ZoomSDKInitParams params = new ZoomSDKInitParams();
params.appKey = "a...t4.."; // TODO: Retrieve your SDK key and enter it here
params.appSecret = "y...19"; // TODO: Retrieve your SDK secret and enter it here
params.domain = "zoom.us";
params.enableLog = true;
// TODO: Add functionality to this listener (e.g. logs for debugging)
ZoomSDKInitializeListener listener = new ZoomSDKInitializeListener() {
/**
* #param errorCode {#link us.zoom.sdk.ZoomError#ZOOM_ERROR_SUCCESS} if the SDK has been initialized successfully.
*/
#Override
public void onZoomSDKInitializeResult(int errorCode, int internalErrorCode) {
Log.i("","onZoomSDKInitializeResult Error code"+errorCode);
Toast.makeText(getApplicationContext()," error code : " + errorCode,Toast.LENGTH_LONG).show();
}
#Override
public void onZoomAuthIdentityExpired() {
System.out.println(" identity expired..");
}
};
sdk.initialize(context, listener, params);
}
findViewById(R.id.login_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "onclick of login", Toast.LENGTH_LONG).show();
Log.i(" ","onclick of login : "+ ZoomSDK.getInstance().isLoggedIn());
if (ZoomSDK.getInstance().isLoggedIn()) {
//wants to create meeting
} else {
createLoginDialog();
}
}
});
private void createLoginDialog() {
new AlertDialog.Builder(this)
.setView(R.layout.dialog_login)
.setPositiveButton("Log in", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
AlertDialog dialog = (AlertDialog) dialogInterface;
TextInputEditText emailInput = dialog.findViewById(R.id.email_input);
TextInputEditText passwordInput = dialog.findViewById(R.id.pw_input);
if (emailInput != null && emailInput.getText() != null && passwordInput != null && passwordInput.getText() != null) {
String email = emailInput.getText().toString();
String password = passwordInput.getText().toString();
if (email.trim().length() > 0 && password.trim().length() > 0) {
login(email, password);
}
}
dialog.dismiss();
}
})
.show();
}
public void login(String username, String password) {
int result = ZoomSDK.getInstance().loginWithZoom(username, password);
if (result == ZoomApiError.ZOOM_API_ERROR_SUCCESS) {
// Request executed, listen for result to start meeting
ZoomSDK.getInstance().addAuthenticationListener(authListener);
}
}
public void onZoomSDKLoginResult(long result) {
if (result == ZoomAuthenticationError.ZOOM_AUTH_ERROR_SUCCESS) {
// Once we verify that the request was successful, we may start the meeting
Toast.makeText(getApplicationContext(), "Login successfully", Toast.LENGTH_SHORT).show();
} else if(result == ZoomAuthenticationError.ZOOM_AUTH_ERROR_USER_NOT_EXIST || result == ZoomAuthenticationError.ZOOM_AUTH_ERROR_WRONG_PASSWORD){
Toast.makeText(getApplicationContext(),"Invalid username or password",Toast.LENGTH_LONG).show();
}
}
Thanks in advance.
I tried with JWT token it works with
https://api.zoom.us/v2/users/me/meetings api. I gave Authorization
token and content-type in headers. it gives me all meetings of that
specific user. but problem to get different authorization token for
different users. I don't have idea is it possible or not.
Assuming these users are not part of the same Zoom account, then no, it is not possible as of 2021-08-28. JWT-based authentication is only for Zoom integration in internal applications/services:
Note: JWT may only be used for internal applications and processes. All apps created for third-party usage must use our OAuth app type.
In this context, "internal" means "only to be used with a single Zoom account." Note that there can be many users under one account (e.g., all employees of Corporation XYZ are part of XYZ's Zoom account). Put differently, you can use a JWT issued for the XYZ Zoom account to access information for all users under the XYZ Zoom account, but if you need data for users that are not part of the XYZ Zoom account, then you need an API Key and API Secret for their Zoom account(s) as well to generate JWTs that you can use to retrieve their data.
If you are building an integration/service that you want to make available to the general public, then you need to use OAuth:
This app can either be installed and managed across an account by
account admins (account-level app) or by users individually
(user-managed app).
I'm about to implement google in app payment into my android app and here's the thing:
I have 3 subscriptions levels, let's say noob, normal and pro. My app have a login/signup, besides of google login. I've already implement all the purchase in my app, but now i'm wondering which is the best practice to attach that premium subs payed with google billing, with my users, so i can check each user in the app even if they're sharing a device with the same google account but different subscription level.
*For example: I'm in 'normal' subscription payed with account asd#gmail.com with username MINE21 in my nexus 5
Then my sister buys a 'pro' subscription payed with account she#gmail.com with
username SHE123 in her Galaxy S6, but then she grab my Nexus 5 and
logins with SHE123 but in playstore i'm logged as asd#gmail.com.
At that moment, i want to show all the pro features to her, but i need
to confirm if SHE123 is premium even if that the playstore account is
asd#gmail.com linked with MINE21.*
If i'm not being clear explaining myself please let me know.
Am i right if i get the userid from the user buying the subscription, and saving it in my database with the google account id, token purchase and premium level?
I wanna know how can i do to check the google payment with each user of my database even if they're using another google account in play store.
--My db is a MySQL database handled with PHP--
Regards,
Inrovero
I'm going to put my process payment here:
private void processPayment(final String SKU){
PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
#Override
public void onPurchasesUpdated(#NonNull BillingResult billingResult, #Nullable List<Purchase> list) {
// To be implemented
if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && list != null){
// do Something you want
Log.i(TAG, "Compra exitosa");
// Preparar categoría de premium
premium = "";
if(list.get(0).getSku().equals(SKU_BS)) premium = "BS";
else if(list.get(0).getSku().equals(SKU_BN)) premium = "BN";
else if(list.get(0).getSku().equals(SKU_BP)) premium = "BP";
Toast.makeText(mContext, premium + " adquirido", Toast.LENGTH_LONG).show();
// Sincronizar premium con la DB y suscripción con el usuario
User currentUser = SharedPrefManager.getInstance(mContext).getUser();
int uid = currentUser.getId();
// Datos a sincronizar
AccountIdentifiers accountIdentifiers = list.get(0).getAccountIdentifiers();
String accID = accountIdentifiers.getObfuscatedAccountId();
String token = list.get(0).getPurchaseToken();
// Pasar a la DB el token, accID y uid vinculados con el premium.
// UID // ACCID // TOKEN // PREMIUM //
}else if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED){
// do Something you want
Log.i(TAG, "Compra cancelada");
// Nada? Cancelar all?
}else if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.ITEM_UNAVAILABLE){
Log.i(TAG, "Item inexistente");
}
}
};
final BillingClient billingClient = BillingClient.newBuilder(mContext)
.setListener(purchasesUpdatedListener)
.enablePendingPurchases()
.build();
billingClient.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(#NonNull BillingResult billingResult) {
if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK){
// The BillingClient is ready. You can query purchases here.
List<String> skuList = new ArrayList<>();
skuList.add(SKU);
SkuDetailsParams params = SkuDetailsParams.newBuilder()
.setSkusList(skuList).setType(BillingClient.SkuType.SUBS)
.build();
billingClient.querySkuDetailsAsync(params, new SkuDetailsResponseListener() {
#Override
public void onSkuDetailsResponse(#NonNull BillingResult billingResult, #Nullable List<SkuDetails> list) {
if(list == null){
Log.i(TAG, "lista vacía");
return;
}
for(int i = 0; i < list.size(); i++){
Log.i(TAG, String.valueOf(list.get(i)));
}
BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
.setSkuDetails(list.get(0))
.build();
int responseCode = billingClient.launchBillingFlow(requireActivity(), billingFlowParams).getResponseCode();
if(responseCode == BillingClient.BillingResponseCode.OK){
// do Something you want
Log.i(TAG, "responseCode OK");
}else if(responseCode == BillingClient.BillingResponseCode.ERROR){
Log.i(TAG, "responseCode ERROR");
}else if(responseCode == BillingClient.BillingResponseCode.ITEM_UNAVAILABLE){
Log.i(TAG, "responseCode ITEM_UNAVAILABLE");
}
}
});
}
}
#Override
public void onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
});
}
When purchase is sucsses send http request to your php server and put the subscription az int
For example int if noob=1 if pro=2
And save it in your database on your server
Than you can create http request from your php to get that number so you know what subscription user have
You can even set string for more understandable form
So if user x have int = 1 you know that is noob subcription
Than do what you want
I hope it will help you figure out
In this android application, I want to get the user data (email id, name, etc) from the authorised google account. In this case I'm caching tokens to see if the user is logged in or not, and if the user is already logged in, it will fetch the basic user data.
The code uses a button to login.
public void login(View view){
if (loadUserTokenCache(mClient)){
TextView tv1 = (TextView)findViewById(R.id.textView2);
tv1.setVisibility(View.VISIBLE);
}
else {
ListenableFuture<MobileServiceUser> mLogin = mClient.login(MobileServiceAuthenticationProvider.Google);
Futures.addCallback(mLogin, new FutureCallback<MobileServiceUser>() {
#Override
public void onFailure(Throwable exc) {
createAndShowDialog("You must log in. Login Required", "Error");
}
#Override
public void onSuccess(MobileServiceUser user) {
createAndShowDialog(String.format(
"You are now logged in - %1$2s",
user.getUserId()), "Success");
cacheUserToken(mClient.getCurrentUser());
}
});
}
}
You can do this using the AccountsManager. For example, this is how you could retrieve the user's gmail.
// Retrieve the gmail associated with the device that is being used.
String gmailID = "";
Account[] accounts = AccountManager.get(getActivity()).getAccountsByType("com.google");
if(accounts.length > 0) {
gmailID = accounts[0].name;
}
I wanted to allow the user to update their email and it works just fine when they enter everything correctly but when they don't something weird happens
So for this example (which is the one that I have been testing) the current user email is email#gmail.com and they want to replace it with h as their email.
Here's the code for updating user email
// get current user
currentUser = ParseUser.getCurrentUser();
// get user input (shortened to show result)
final String email = "h";
// reset user email
currentUser.setUsername(email);
currentUser.setEmail(email);
// save progress
currentUser.saveInBackground(new SaveCallback()
{
#Override
public void done(ParseException e)
{
if (null == e)
{
// success
// tell user of success
Toast.makeText(getActivity(), "new email is " + email,
Toast.LENGTH_SHORT).show();
// restart activity to update information
restartActivity();
}
else
{
// update failed
// look at the ParseException to see what happened.
errorMessageDialog("Oops!", e.getMessage());
}
}
});
So obviously there will be a parse exception thrown and it will be that it is not a valid email address and when I check the database that is the case. Nothing was updated in any of the rows; however, if I check the current email later on then something unexpected happens
// get current user
currentUser = ParseUser.getCurrentUser();
// get username
currentUser.getUsername();
// get email
currentUser.getEmail();
When I run that code, it says my email and username are h but if I check the database it's still example#gmail.com
It appears that parse still updates it's local cache even when there was an exception thrown from the database? I don't know what the problem is perhaps saveInBackground(new SaveCallback() is the wrong method to use?
I am using Android Studio for my app and Parse for my database... and on the create an account page I have, it allows the user to enter in first name, last name, email, username, and password.
But my code is using parseUser... I don't know how to set the first and last name in the database.
I know setUsername, setPassword, setEmail is a part of it... but what about if you make a column in Parse? How can you add this in your class?
This is a part of my code, what it looks like...my problem is in the else statement I have:
// Force user to fill up the form
if (usernametxt.equals("") && passwordtxt.equals("") && emailtxt.equals("")) {
Toast.makeText(getApplicationContext(),
"Please fill in the username, password, and email fields.",
Toast.LENGTH_LONG).show();
} else {
// Save new user data into Parse.com Data Storage
ParseUser user = new ParseUser();
//somehow save first and last name
user.setEmail(emailtxt);
user.setUsername(usernametxt);
user.setPassword(passwordtxt);
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
Yes, Parse does provide methods to save username, passwords like setUsername(params) and setPassword(params) but if you want to add more data to the tables, you can create more columns according to your needs as I did in this code snippet.
If you have come columns created already in parse back-end like name, phone,address,cityState,companyId, this is how I am doing it.
private void savetoParse() {
ParseUser user = new ParseUser();
user.setUsername(usernameEditText.getText().toString());
user.setPassword(passEditText.getText().toString());
user.put("name", nameEditText.getText().toString());
user.setEmail(emailEditText.getText().toString());
user.put("phone", phoneNoEditText.getText().toString());
user.put("address", addressEditText.getText().toString());
user.put("cityState", cityStateEditText.getText().toString());
user.put("companyID", compSchoolIdEditText.getText().toString());
user.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
Toast.makeText(SignupActivityUpdate.this,
"Saving user failed.", Toast.LENGTH_SHORT).show();
Log.w(TAG,
"Error : " + e.getMessage() + ":::" + e.getCode());
if (e.getCode() == 202) {
Toast.makeText(
SignupActivityUpdate.this,
"Username already taken. \n Please choose another username.",
Toast.LENGTH_LONG).show();
usernameEditText.setText("");
passEditText.setText("");
confirmPassEditText.setText("");
}
} else {
Toast.makeText(SignupActivityUpdate.this, "User Saved",
Toast.LENGTH_SHORT).show();
/*Do some things here if you want to.*/
}
}
});
NOTE : The first params is the column name and second is the value. So, it basically acts like a key value pair.
This is solve the problem..lemme know if this works..good luck..:)
/**
* user Registration here
* save user registration value on server here
*/
private void userRegistration()
{
progressDialog=new ProgressDialog(SignUpThirdPage.this);
progressDialog.setMessage("Please Wait......");
progressDialog.setCancelable(false);
progressDialog.show();
ParseUser user = new ParseUser();
user.setUsername("Name");
user.setPassword(strPassword);
user.setEmail(strEmailId);
// surName column create on parse.com db you can check after run that code
// like that u can add more column in signup table
user.put("surName","Kumar");
user.signUpInBackground(new SignUpCallback() {
#Override
public void done(com.parse.ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
}
} else {
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
e.printStackTrace();
progressDialog.dismiss();
if(e.getMessage().contains("already taken")){
alertDialog("", "you've already sign up , lets login in ", SignUpThirdPage.this, false);
}
else if(e.getMessage().contains("has already been taken")){
alertDialog("", "you've already sign up , lets login in ", SignUpThirdPage.this, false);
}
else {
AppConstants.showAlertDialog("", e.getMessage(), SignUpThirdPage.this, false);
}
}
}
});
}