How to select distinct values from ORMlite? - android

I want to get distinct values from Database. Currently I am using ORMlite. I have tried the following code. But still I am getting repeated values from, when I am querying. Could anyone point out where I have gone wrong? I am posting the sample code below
smsDao = databaseHelper.getSmsDao();
QueryBuilder<SMSObject, Object> queryBuilder = smsDao.queryBuilder();
queryBuilder.distinct().selectColumns("timestamp");
try {
preparedQuery = queryBuilder.prepare();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
smsObject = smsDao.query(preparedQuery);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Any help is appreciable.

dataList = Utils.getDBHelper(ItemList.this).getItemDao().queryBuilder().where().in("nameid", lis).query();
This is the code I used earlier in my app. It was retrieving duplicate values from the database. Then I updated it with the distinct() method and everything started to work fine.
dataList = Utils.getDBHelper(ItemList.this).getItemDao().queryBuilder().distinct().where().in("nameid", lis).query();
Note: Here 'lis' is the iteratable list in which my search parameters are added. If you don't have one, you can use 'eq()' instead of 'in()'.

Related

Updating existing record in parse.com not working it doing duplication

I am working on parse.com demo, I want to update an existing entry from a table in parse.com. Each time it makes a duplicate entry. I have tried what's below.
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("MQOD");
// query.orderByDescending("createdAt");
query.whereEqualTo("DeviceId", android_id);
// query.toString();
System.out.println("::::::::::::::::::QUERY:::::::::::::::"
+ query);
try {
ob = query.find();
} catch (com.parse.ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
testObject.put("DeviceId", android_id);
testObject.put("InstallationDate", subscriptionDate);
testObject.put("Subscription", "Done");
testObject.put("NextSubscription", upGradeDate);
try {
testObject.save();
} catch (com.parse.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
// Purchase error...!!
System.out.println("::::::::::::::::::::::::Purchase consumehas failed:::::::::::::::::::::");
}
}
From your code seems that you don't use the standard field id objectID( that is the official id field used in all the Parse class table ) but the DeviceId ( i suppose it is your custom field ) .
Otherwise you have to make your DeviceId as unique field, and to make it possible, you have to check the new incoming DeviceId in the "beforeSave" parse trigger, and so check if the element already exist or not ( see also this: https://www.parse.com/questions/unique-fields--2 )
So, at now it's normal that you obtain a dubplicate each time, because it is considered as Insert instead of Update ( since you don't specify the objectId )
Hope it helps

Upload comments to particular post of facebook with object_id android

Hello friends I want to post comment to particular post in facebook with my android app, below is my code-
I Fetch All comments from URL which is below
http://retirementhomeslisting.com/home-detail/canterbury-place-83
Bundle mBundle=new Bundle();
mBundle.putString("message","testing...1234555");
#SuppressWarnings("deprecation")
Facebook fb=new Facebook(getResources().getString(R.string.fb_app_id));
try {
fb.request("478409145610921/comments",mBundle,"POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Here I provide one link which you can see all comment list with respective above object_id
Link for comment list for 478409145610921 object_id
When i run above code comment is not post with respective object_id so Any idea how can i solve it?
EDIT Answer
Bundle mBundle=new Bundle();
mBundle.putString("message","testing...1234555");
#SuppressWarnings("deprecation")
Facebook fb=new Facebook(getResources().getString(R.string.fb_app_id));
try {
fb.request("1309634065_478409145610921/comments",mBundle,"POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
To post a comment on a post, you need a post_id instead of object_id.
So your API call must be-
/{post_id}/comments
(post_id is also a field in the comments table)
Edit:
You must be using a comment plugin and trying to post a comment to that. Unfortunately, facebook don't allows you to do that! (Logical- since most of them are public, to avoid spamming, else anyone could flood comments to that post)
If you check the response here, you'll get:
{
"error": {
"message": "(#100) Comments may not be added to a comment plugin",
"type": "OAuthException",
"code": 100
}
}
You can test these API call on Graph API Explorer also.
Using Graph API:
...
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"]) {
[[[FBSDKGraphRequest alloc]
initWithGraphPath:#"post_id/likes"
parameters: #{ #"like" : #"true"}
HTTPMethod:#"POST"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(#"It was liked.");
}
}];
}
...

Not able to Post facebook Checkin status Android

Error:
Response={ "error": { "message": "(#100) Requires extended permission: publish_checkins or publish_actions", "type": "OAuthException", "code": 100 }}
Source Code:
Bundle params1 = new Bundle();
params1.putString("access_token",token);
params1.putString("place", "566414493392930"); // YOUR PLACE ID
params1.putString("message","I m here in this place");
JSONObject coordinates = new JSONObject();
try {
coordinates.put("latitude", "30.902823300000000000");
coordinates.put("longitude", "75.830516900000020000");
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
params1.putString("coordinates",coordinates.toString());
params1.putString("tags",params[0]);//where xx indicates the User Id
String response="";
try {
response =faceBook.request("me/checkins", params1, "POST");
Log.v("Response","Response="+response);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Well, the error says that the permissions: publish_checkins or publish_actions is required. To remove this error, simply add these permissions while authenticating the user. See how it is done: Android login- permissions
But, the thing is- the API checkins have been deprecated. Check here it says-
Checkins have been deprecated in favor of attaching place information to posts, or tagging places in Open Graph stories. Please check the related guides for information.
So your code shall not work anyway. You'll now have to use Open Graph Actions for the same. There's step wise tutorial for the same in the documentation, just go through it and implement. Good luck.

Android: Need help, trying to parse a HTML page using JSoup parser

Here is the code so far I am trying but it is showing me error:
URL url = null;
try {
url = new URL("http://wap.nastabuss.se/its4wap/QueryForm.aspx?hpl=Teleborg+C+(V%C3%A4xj%C3%B6)");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("1");
Document doc = null;
try {
System.out.println("2");
doc = Jsoup.parse(url, 3000);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("3");
Element table = doc.select("table[title=Avgångar:]").first();
System.out.println("4");
Iterator<Element> it = table.select("td").iterator();
//we know the third td element is where we wanna start so we call .next twice
it.next();
it.next();
while(it.hasNext()){
// do what ever you want with the td element here
System.out.println(it.next());
//iterate three times to get to the next td you want. checking after the first
// one to make sure
// we're not at the end of the table.
it.next();
if(!it.hasNext()){
break;
}
it.next();
it.next();
}
It prints System.out.println("3");
then it stops in this line
Element table = doc.select("table[title=Avgångar:]").first();
How can i solve this problem,
Thanks
It looks like the website you're trying to parse the HTML from has an error and doesn't have any tables on it. This is what's causing the null pointer exception. doc.select("table[title=Avgångar:]") isn't returning an element and then you're trying to call a method on it. To prevent this error from happening again, you could do something like this:
Elements foundTables = doc.select("table[title=Avgångar:]");
Element table = null;
if(!foundTables.isEmpty()){
table = tables.first();
}
Now, if any table was found, the table variable won't be null. You'll just have to alter the code to adapt in case no tables are found.
You're not checking the result of doc.select() before calling .first(). If there are no elements in the document that match the specified query, doc.select() could return null. Then you are calling .first() on a null pointer which, of course, will throw an exception. There is no table tag with the title you have specified in the document that you are using in your example. So, the result is not surprising.

Can`t insert a new record into contacts

I can successfully insert a new record using People.CONTENT_URL according to http://developer.android.com/guide/topics/providers/content-providers.html#addingrecord.
But the People class is deprecated, So i would like to using ContentProviderOperation and Data.CONTENT_URL to insert record. here is my code.
super.onCreate(savedInstanceState);
ArrayList operations = new ArrayList();
operations.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
.withValue(Phone.CONTACT_ID, "23").withValue(CommonDataKinds.Phone.NUMBER,
"13412341234123412341234").build());
try {
getContentResolver().applyBatch(ContactsContract.AUTHORITY, operations);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (OperationApplicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
According to my understanding, you simply want to add a new contact, right?
I have answered the question Here. I have used the same piece of code and it works for me.
If you are trying to add a new contact try this code :
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME, "name");
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "123456");
startActivity(intent);

Categories

Resources