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);
Related
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
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.");
}
}];
}
...
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.
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()'.
I could build a sip profile using SipProfile.Builder class. I used following snippet of code to do it:
if (SipManager.isApiSupported(MyActivity.this)&& SipManager.isVoipSupported(MyActivity.this)) {
SipManager manager=SipManager.newInstance(this);
SipProfile.Builder builder;try {
builder = new Builder(userName,domainName);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} manager = SipManager.newInstance(MyActivity.this);
builder.setPassword(password);
profile = builder.build();
try {
manager.open(profile);
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
manager.register(profile, 30, MyActivity.this);
} catch (SipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(MyActivity.this, "created",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(MyActivity.this, "Not Supported",
Toast.LENGTH_LONG).show();
}
It shows as a sip account in the settings/callsettings/Internet call settings.
Problem is i could not make it as primary account. How can i make it as primary account?
This information is account-based (primary email address for person, primary phone number, primary SIP account etc.) so it's stored in the phone's contacts-book.
It seems to me it's an option that is set per-data, per-account (for example: this type of data (email/phone/sip-addr) set it as primary).
You can set data as primary for a contact using IS_PRIMARY or IS_SUPER_PRIMARY
IS_PRIMARY: Whether this is the primary entry of its kind for the raw
contact it belongs to.
The data you should use it on is ContactsContract.CommonDataKinds.SipAddress. I hope that's useful as starting point.