I´m coding an app that will allow the user to take a picture, add some title and description to it and upload it to Google´s Servers. That package (picture+title+description) is named "Gift". I've used Google´s automated Backend Engine generator and added an #Entity class named Gift.
After taking the picture and clicking on submit, the "Gift" is successfully sent to Google and looking my Google App Engine Dashboard, now I have a Gift with a proper ID, a Blob (image), Description and Title.
Now what I want to do is show all those "Gifts"/Entities on a ListView, so that the user can interact with the "Gifts". What is the best way to do that?
I think I found the answer, here´s the code I´m using:
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Filter keyFilter = new FilterPredicate(Entity.KEY_RESERVED_PROPERTY,
FilterOperator.GREATER_THAN,
0);
Query q = new Query("Gift").setFilter(keyFilter);
PreparedQuery pq = datastore.prepare(q);
for (Entity result : pq.asIterable()){
String title = (String) result.getProperty("title");
String description = (String) result.getProperty("description");
Blob bmp = (Blob) result.getProperty("bmp");
//new Object using variables above
}
This way I think I can iterate through the results and associate them with new objects of the type Gift.
Related
I'm making an app that uses coupons. I want to know programmatically what is the coupon code that the user has entered and based on the input do the stuff.
For example, I have added manually to Cloud Firestore a code for signing up. How do I check in the app that this is the code used for signing up and the user has entered? And based on that coupon code do what should be done.
Database image
Any help?
Get the coupon code from the user in a EditText
Get the coupon code from Firebase
Compare both with
String inputCode = editText.getText().toString();
String cloudCode = task.getString("code");
if (inputCode.equals(cloudCode)){
//do your thing
}
here task is from firebaseFirestore.collection().get();
Edit 1:
Things to do before implementing Coupons
All coupon code should follow a Pattern
Pattern eg - SALE0040 or SIGN0050 or DISC0020
Patter like - ABCD0123 or anything suits your needs
Your code will understand the type by looking at 1st half - SIGN and it will understand how much discount to give with 2nd half - 0050
code -
String couponCode = task.getString("coupon");
String userCode = editText.getText().toString();
String type = couponCode.subString(0,4);
int discount = Integer.valueOf(couponCode.subString(4,couponCode.length()));
Same you can do with the user entered code
Now you have both values of both Coupons Discount/Coupon type and Discount amount
Assuming you have an EditText, to get the code that is entered by the user you should use the following line of code:
String coupon = editText.getText().toString().trim();
Now having this coupon you can search the database to see if it actually exists, using the following query:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference couponsRef = rootRef.collection("Coupons");
Query query = couponsRef.whereEqualTo("coupon", coupon);
query.get().addOnCompleteListener(/* ... */);
Edit:
If the code is only for signup, then you should add a new property under your coupon object named type and use the following query:
Query query = couponsRef.whereEqualTo("coupon", coupon).whereEqualTo("type", "signup");
Another way to solve this might be to get the name of the coupon and check if it starts with SIGNUPCOUPON.
i have made a qr scanner in android that sends the value to google sheets using dopost() now i want to setup a trigger to automatically send mail to the user whenever a new row is inserted into the google sheets.
I have tried onEdit() and onChange() but it's not working
Did you create a web app to insert data into a Spreadsheet? Your question suggests that because you say when user information is inserted into a new row using doPost(). So to be clear doPost() and doGet() are used to support get requests and posts from a webapp. If that is what you are doing then please make it more clear.
But it sounds to me that your expecting the onEdit() to trigger a change when the webapp changes the data in the spreadsheet. Unfortunately, that's not going to happen. The documentation from Simple Triggers states onEdit(e) runs when a user changes a value in a spreadsheet. not when your script changes a value.
But really why don't you just send the email when you update the spreadsheet information with another Google Apps Script.
Question Response
Since your using doPost() why don't you just use a form and then you don't have pass everything in the query string.
function addItem(e){
var ss = SpreadsheetApp.openByUrl("url");
var sheet = ss.getSheetByName('Sheet1');
var date = new Date();
var Roomnumber = e.parameter.Roomnumber;
var email = e.parameter.email;
sheet.appendRow([date,Roomnumber,email]);
}
function sendEmails() {
var ss = SpreadsheetApp.openByUrl("url");
var sheet = ss.getSheetByName('Sheet1');
var range = sheet.getRange(sheet.getLastRow(),1,1,3);
var values = range.getValues;
var date=values[0][0];
var roomnumbeer=values[0][1];
var email=values[0][2];
//code to send mail
}
We have API that gives us the valuation of the car:
We have built in form in our android app that has input fields as :- car version, car make year.
So, we have built input form as:
Drop down that lets users select the version of the car.
A free text field that lets users type year of manufacturing of the car.
Finally we give user submit button, once user clicks here, we pass data to valuation api:
/api/valuation/?versionid=23&year=2010
The api returns back valuation of that car i.e.$20000.
In future, we will improve this algorithm and we will include kilometers etc. field in the API?
HATEOS suggests that every action except first API action should be guided through server. How can we let server create such dynamic valuation API url so that if more fields are introduced in API, android/ios sends back these added fields in the query string params?
Something like this...
private String buildUrlService() {
String url = "www.xpto.com/api/?";
if(edittextvalue.getText().toString() != null) {
url = url + "version=" + edittextvalue.getText();
}
return url;
}
I am new to this stuff, so I hope my question makes sense..
Basically what I want to be able to do is GET and POST data to the Google App Engine server I am running. Then, I want to be able to retrieve that same data from other devices that are accessing the server.
So let's say a user runs my app, enters in a String: "blue", and through some API that I define in an endpoint, my app takes that String and sets a GLOBAL variable that exists on my server equal to that string. ( String color = "blue" )
Then, if another user opens my app, I want him/her to be able to see color = "blue" because it has been set by another user, and if this other user wants to change the color to color = "pink", then it will change across all devices again!
So, I know how to create an API / API method, as described in the Cloud-endpoints tutorial. Example :
public class MyEndpoint {
#ApiMethod(name = "sayHi")
public MyBean sayHi(#Named("name") String name) {
MyBean response = new MyBean();
response.setData("Hi, " + name);
return response;
}
}
But how would I go about achieving what I have described above?
You cannot set "global" variables on GAE as your instances are constantly being created and destroyed to manage user traffic.
You'll have to use a shared instance like Memcache (volatile) or datastore (persistent) to reuse values across instances
I'd like the use the getSkuDetails() call from the In-app Billing v3 API to dynamically display a list of inapp purchase options with properly translated titles and relevant price.
However, the "title" property from getSkuDetails() seems to always be of the form "<item title> (app name)", which is less than useful. How can I get only the item title itself without the app name without hacking the string?
That is the way it is. I mean even I didn't like it, obviously user knows that he is buying from the app but I think Google is going to reply it in this way only
As no one has replied with an actual regex pattern to match the app name in parentheses in the SKU title I thought I just post the code here for further reference:
// matches the last text surrounded by parentheses at the end of the SKU title
val skuTitleAppNameRegex = """(?> \(.+?\))$""".toRegex()
val titleWithoutAppName = skuDetails.title.replace(skuTitleAppNameRegex, "")
The regex is as strict as possible to allow for additional text in parentheses within your SKU title without removing it as well (e.g. SKU titles like Premium (Subscription) would stay as they are). The only thing you should avoid is parentheses in your app name, but with a little tweaking of the regex you could work around that as well.
As regexes are notoriously expensive to build it is advisable to store it in a field and avoid constructing them each time over when you are parsing your SKUs.
Adapting #ubuntudroid answer to Java, I made it work like this:
String skuTitleAppNameRegex = "(?> \\(.+?\\))$";
Pattern p = Pattern.compile(skuTitleAppNameRegex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(skuDetails.getTitle());
String titleWithoutAppName = m.replaceAll("");
String productTitleWithAppName=skuDetails.getTitle();
String productTitleWithoutAppName = productTitleWithAppName.substring(0, productTitleWithAppName.indexOf("("));
You don't need to use regex for this. The following should work. This is in C# but you can guess how you can do it in Java or any other language.
string title = getTitle(); // get title
int appNameStartIndex = title.LastIndexOf("("); // find last index of (.
string titleWithoutAppName = title.Substring(0, appNameStartIndex); // and :)
In fact, the name of the SKU without the app name in parantheses is transfered with the SKU, but there is no getter to retrieve it.
If you have a deeper look into the implementation of SkuDetails class, then you see, that this whole thing is based on a json String (also debugging gives you this json).
And this json string contains not only the title with the apps name, but also a name field with the SKUs name only.
The SKUs json representation can be retrieved with SkuDetails.getOriginalJson().
So if it better fits your needs, then you can of course retrieve the SKU name directly from the data, returned from Google.
I found that in development builds, I'd get a value like My product (com.test.myapp (unreviewed)). Here's a version of the regex that handles the nested parentheses and keeps other parentheses in your product name intact:
const removeAppNameFromProductTitle = (title: string) => {
const regex = /( \([^()]*\)$)|( \([^)]*\)\)$)/im;
return title.replace(regex, '');
};
The code is in TypeScript (React Native), but I'm sure you can adapt. Here's a gist with test cases: https://gist.github.com/thmsobrmlr/732ecf958f600ec38e89c4e8ff57f3dd.