Harry
 Total thread: 131 Total reply: 50
Post #150 | How to use parse.com for Android - Register account in parse.com, get the "ApplicationId" and "ClientKey"
- Copy 2 jars ("bolts-android-1.1.3.jar" and "parse-1.7.1.jar") to project's "libs" folder
- Init the parse.com library in Activity.onCreate(), such as:
''.str_replace(' ', '
', ' Parse.initialize(this, ParseApplicationId, ParseClientKey); ').' '
- To query data, example code snippet:
''.str_replace(' ', '
', ' showProgressBar(true);
ParseQuery<ParseObject> query = ParseQuery.getQuery("myClass"); query.whereEqualTo("deviceId", deviceId); query.findInBackground(new FindCallback<ParseObject>() { @Override public void done(List<ParseObject> foundList, ParseException e) { if (e == null) { int iTotalRow = foundList.size(); Log.d(TAG, "Retrieved " + iTotalRow + " rows"); if(iTotalRow < 1) { Log.d(TAG, "device is NOT registered yet"); // deviceId is not found == not register registerDevice(); } else { Log.d(TAG, "device already registered"); } } else { Log.e(TAG, "Error: " + e.getMessage()); registerDevice(); } showProgressBar(false); } }); ').' '
- To store data, example code snippet:
''.str_replace(' ', '
', ' showProgressBar(true); ParseObject deviceObject = new ParseObject("myClass"); deviceObject.put("deviceId", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_ID)); deviceObject.put("deviceScreenSize", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_SCREEN_SIZE)); deviceObject.put("deviceScreenWidth", HSharedPreferences.getIntData(MainActivity.this, HSharedPreferences.KEY_DEVICE_SCREEN_WIDTH)); deviceObject.put("deviceScreenHeight", HSharedPreferences.getIntData(MainActivity.this, HSharedPreferences.KEY_DEVICE_SCREEN_HEIGHT)); deviceObject.put("deviceMACAddress", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_MAC_ADDRESS)); deviceObject.put("deviceModel", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_MODEL)); deviceObject.put("devicePhoneNumber", HSharedPreferences.getData(MainActivity.this, HSharedPreferences.KEY_DEVICE_PHONE_NUMBER));
deviceObject.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { if(e == null) { Log.d(TAG, "save completed"); } else { Log.e(TAG, "save failed: " + e.getLocalizedMessage()); }
showProgressBar(false); } }); ').' '
NOTE: FREE usage for parse.com has limitation, one of them is 30 operations per seconds, if we want to get more operations then we must pay. Falling in love with the world
Write : 2015-01-07 14:25:29 Last edit : 2015-01-07 14:35:25 |