phone gap adding contacts problem - android

iam just practicing with phone gap for android app. I found a piece of code in docs.phonegap.com, regarding adding contacts
function onDeviceReady()
{
alert('onDeviceReady: PhoneGap1');
var myContact = navigator.contacts.create({"displayName": "Test User"});
alert('onDeviceReady: PhoneGap2');
myContact.gender = "male";
console.log("The contact, " + myContact.displayName + ", is of the " + myContact.gender + " gender");
}
When i run this i am getting only the alert box and the name is not added in my contacts. How to add the contacts....
Please tell me how to add data and open the device default contacts...

Simon Mac Donald has written a great blog post on contacts with PhoneGap and Android.
http://simonmacdonald.blogspot.com/2011/09/saving-contacts-with-phonegap-android.html
It should help you out as there are a few steps to it.

The quick answer for those of you searching, is that you have to call
myContact.save()
in order to persist the contact that you just created.

Related

Delete pre-populated sqlite database when update in cordova

I have completed my project which contains a pre populated sqlite database.
I have found this plugin and it works for me nicely. Lifehelper's products are truly remarkable and they have maintain pretty nice documentation.
However, when i open database, i use this format which is suggested their documentation for pre populated database.
var db = window.sqlitePlugin.openDatabase({name: "my.db", location: 'default', createFromLocation: 1});
However, my database is only for information. Application only read data from pre populated database. There is no any insert, update or delete query to keep per any user information.
In every new version pre populated data could modified, updated by me. So I need completely new app install along with new database when user will update their app.
But unfortunately, my app could not delete previous database. Changing version code also not working.
Someone suggest me, its about location which i am using to open database. But i can not understand how should dealing with it.
Help me, best answer is more important to me. Thanks.
To avoid increasing app size, you can do something like this:
function cleanupDatabases() {
var oldDatabases = ["2.1.0.db", "2.0.0.db"];
if (window.sqlitePlugin !== undefined) {
angular.forEach(oldDatabases, function(db) {
window.sqlitePlugin.deleteDatabase({
name: db,
location: 2
}, function() {
console.log("%c " + db + " is deleted", "background: green; color: white");
}, function(error) {
console.log("%c " + db + " could not be deleted", "background: red; color: white", error);
});
});
}
};

jQuery .load() stops complete script on iPhone/Android without error message

Since I add the following lines to mij jQuery script, the whole jQuery is not working anymore on Mobile Devices. On all the PC browsers everything works fine
if ( $("input[name=campaign_id").val() ) {
$('#address').load('/Xscripts/fetch_users_data.php?cid=' + $("input[name=campaign_id").val(), function(responseTxt, statusTxt, xhr){
if(statusTxt == "error")
alert("Error by loading data: " + xhr.status + ": " + xhr.statusText);
});
};
There is no error message, but just all the jQuery functions are completely not working.
Does anyone have any clue how to fix this? How can this load code make the complete jQuery-script crashing on iPhone and Android? Removing these lines makes the rest of the script running again.
Many thanks in advance,
NiFa
OK lets try some things
1st close input attr with ] .. replace a next code in both places
$("input[name=campaign_id]").val()
------^------
2nd for load url you can try
'Xscripts/fetch_users_data.php?cid=' + $("input[name=campaign_id]").val()
or
'./Xscripts/fetch_users_data.php?cid=' + $("input[name=campaign_id]").val()
hope it helps

Titanium: Show and Create Contact Intent

I was trying to export contacts from my application to the native android contacts.
I found the following solution here on this site: Titanium: How to add Contact in Phone book in Android?.
And it kinda works. The intent gets started. Only problem is, that android does not recognize most of the Extras i put in. So almost every field is blank. It does not matter if I replace contactModel with a simple String, the result is the same.
So i was wondering if the keys are simply wrong, but there seems no proper documentation on appcelerator. Probably something has changed over the past years or I am just missing something. Does anybody know how to do it the right way.
Code Snippet:
if (OS_ANDROID) {
var intent = Ti.Android.createIntent({
action : 'com.android.contacts.action.SHOW_OR_CREATE_CONTACT',
data : 'mailto:' + contactModel.get('contact_first_name') + ' ' + contactModel.get('contact_last_name')
});
intent.putExtra('email', contactModel.get('contact_email'));
intent.putExtra('email_type', 'Work');
intent.putExtra('phone', contactModel.get('contact_mobile_number'));
intent.putExtra('phone_type', 'mobile');
intent.putExtra('name', contactModel.get('contact_first_name') + ' ' + contactModel.get('contact_last_name') );
intent.putExtra('address', addressModel.get('address_street') + ", " + addressModel.get('address_city'));
intent.putExtra('address_type', 'Work');
Ti.Android.currentActivity.startActivity(intent);
}
Thx in advance. :)
The first parameter of putExtra() also accepts one of the constants Ti.Android.... So instead of email you would probably have to use Ti.Android.EXTRA_EMAIL.
I think you can find quite a lot in the docs, e.g. here:
EXTRA constant properties in Ti docs
EXTRA constants in Android docs
Android Intents in Ti docs

Android Query for Bookmarks not filtering in Jelly Bean

Looking for some help regarding querying in different verions of Android. I have the following code that returns a cursor of bookmarks. I am trying to filter the browser to return only urls that are actual bookmarks, not just browser history. It works on version 3.1 but on my new Nexus 7, it will not filter by bookmark, but instead returns all browser history in the cursor. Any insight is much appreciated. I think I have run into issues with filtering and content resolver query's not paying attention to selection parameters but can't seem to find any info. Thanks.
String[] mColumnStrings =
{
Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL,
Browser.BookmarkColumns._ID,
Browser.BookmarkColumns.BOOKMARK
};
try{
bookmarksCursor = getActivity().getContentResolver().query(Browser.BOOKMARKS_URI, mColumnStrings, Browser.BookmarkColumns.BOOKMARK+ " = 1 ", null , Browser.BookmarkColumns.URL + " ASC");
getActivity().startManagingCursor(bookmarksCursor);
return bookmarksCursor;
Its working fine for me...I tested it on AVD...actually Android 4.1 already have some default bookmarks...print the Browser.BookmarkColumns.BOOKMARK as well to verify weather the results are bookmarked or not...
You can use this method specifically for your to varify...
private void varify(Cursor bookmarksCursor) {
bookmarksCursor.moveToFirst();
while(bookmarksCursor.moveToNext()) {
Log.v("title", bookmarksCursor.getString(0));
Log.v("url", bookmarksCursor.getString(1));
Log.v("id", bookmarksCursor.getString(2));
Log.v("bookmark", bookmarksCursor.getString(3));
}
}
Hope this works...
If you decide that this answers your question, please mark it as "accepted". This will raise both your and my reputation score.

Create a pre filled contact with the standard Activity

In my app i'm trying to create a Contact by calling the standard Create/Edit contact Activity.
I've found how to make it work but not exactly the way I like.
For now I manage to call the standard create contact activity with the following intent extra:
Intent i = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, Uri.parse(String.format("tel: %s", data.getPhone())));
i.addCategory(Intent.CATEGORY_DEFAULT);
i.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true);
i.putExtra(ContactsContract.Intents.Insert.NAME, data.getName());
i.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
i.putExtra(ContactsContract.Intents.Insert.PHONE, org.getPhone());
i.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
i.putExtra(ContactsContract.Intents.Insert.POSTAL, org.getAddress() + " " + org.getZipCode());
i.putExtra(ContactsContract.Intents.Insert.EMAIL_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
i.putExtra(ContactsContract.Intents.Insert.EMAIL, org.getEmail());
startActivity(i);
All the data is filled properly except the address field as you can see in the following picture: http://img689.imageshack.us/img689/1073/capturevvm.png
I'd like to specify each part of the address in the separate field. Is there a way to do it with an Intent?
I tried this, but it did not work.
i.putExtra(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
i.putExtra(ContactsContract.CommonDataKinds.StructuredPostal.STREET, "toto");
i.putExtra(ContactsContract.CommonDataKinds.StructuredPostal.CITY, "paris");
Any idea?
contactIntent.putExtra(ContactsContract.Intents.Insert.POSTAL, "2 rue de Romme, 75000 Paris");
contactIntent.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
You can add the contact using the technique at New contacts created using ContactsContract do not appear in Contacts app
Then show it using your technique.

Categories

Resources