I've been trying to get my app to delete contacts from the an android phone using C# and Xamarin Forms. I would like to be able to search for a contact by the contact's display name and then delete it from the contacts.
Any help would be greatly appreciated.
Edit
I have now been able to delete all contacts from the phone in one go, but I still want to be able to delete selected contacts using the display name to identify the contact. This is my code, what changes would I have to make to be able delete selected contacts?
List<ContentProviderOperation> ops = new List<ContentProviderOperation>();
ops.Add(ContentProviderOperation.NewDelete(ContactsContract.RawContacts.ContentUri).Build());
Android.App.Application.Context.ContentResolver.ApplyBatch(ContactsContract.Authority, ops);
So after a lot of work on it this is my solution. ToDelete is the string I have passed in the compare to the display name of the contact.
Context thisContext = Android.App.Application.Context;
string[] Projection = new string[] { ContactsContract.ContactsColumns.LookupKey, ContactsColumns.DisplayName };
ICursor cursor = thisContext.ContentResolver.Query(ContactsContract.Contacts.ContentUri, Projection, null, null, null);
while (cursor != null & cursor.MoveToNext())
{
string lookupKey = cursor.GetString(0);
string name = cursor.GetString(1);
if (name == ToDelete)
{
var uri = Uri.WithAppendedPath(ContactsContract.Contacts.ContentLookupUri, lookupKey);
thisContext.ContentResolver.Delete(uri, null, null);
cursor.Close();
return;
}
}
Related
I'm currently working on a JavaFX project.I'm using Autcomplete TextField of ControlFx .Each time i add new rows in database table, it should to update Autocomplete ,i did this but my problem is showing double Context-Menu ,we can say double autocompletes because i call method that create autocomplete each adding of new elements in table.
When i click a tab editBill i call this method :
public void showEditBill() {
if (!BillPane.getTabs().contains(EditBillTab)) {
BillPane.getTabs().add(EditBillTab);
}
SingleSelectionModel<Tab> selectionModel = BillPane.getSelectionModel();
selectionModel.select(EditBillTab);
/*it should remove the old autocomplete from textfield*/
pushBills(); //Call for cheking new items
}
pushBills method () :
public void pushBills() {
ArrayList list = new ArrayList<>();
bills = new BillHeaderDao().FindAll();
for (int i = 0; i < bills.size(); i++) {
list.add(bills.get(i).getIdClient());
}
//How can i remove the old bind before bind again
autoCompletionBinding = TextFields.bindAutoCompletion(SearchBill, SuggestionProvider.create(list));
}
How i can remove the old autocomplete and bind new automplete?
Just in any case if you need to keep instance of AutoCompletionTextFieldBinding object, thus avoiding use of:
autoCompleteBinding = TextFields.bindingAutoCompletion(TextField,List);
, which will change the instance, we could go a little bit deeper and use this:
// let's suppose initially we have this possible values:
Set<String> autoCompletions = new HashSet<>(Arrays.asList("A", "B", "C"));
SuggestionProvider<String> provider = SuggestionProvider.create(autoCompletions);
new AutoCompletionTextFieldBinding<>(textField, provider);
// and after some times, possible autoCompletions values has changed and now we have:
Set<String> filteredAutoCompletions = new HashSet<>(Arrays.asList("A", "B"));
provider.clearSuggestions();
provider.addPossibleSuggestions(filteredAutoCompletions);
So, through SuggestionProvider, we have "updated" auto completion values.
To avoid doubling of suggestions menu, don't use again (for the 2nd time):
TextFields.bindAutoCompletion(..)
In order to provide updates to the auto-complete suggestion list, retain a reference to the SuggestionProvider and update the suggestion provider instead:
TextField textField = new TextField();
SuggestionProvider suggestionProvider = SuggestionProvider.create(new ArrayList());
new AutoCompletionTextFieldBinding<>(textField, suggestionProvider);
When you want to update the suggestion list:
List<String> newSuggestions = new ArrayList();
//(add entries to list)
suggestionProvider.clearSuggestions();
suggestionProvider.addPossibleSuggestions(newSuggestions);
This will do the trick:
Instead of: TextFields.bindAutoCompletion(textField, list);
, try this:
List<String> strings = new ArrayList<>();
Then create binding between your textField with the list through:
new AutoCompletionTextFieldBinding<>(textField, SuggestionProvider.create(strings));
So any changes, including removing, from the list, will be reflected in the autoCompletion of the textField;
And you will have dynamic filtering of suggestions, showed in pop-up, when user enter some text in textField;
I had the same problem some time ago I try to do as #MaxKing mentions, but it didnt work. I managed to give it a soluciĆ³n even though I don't think it's the right way.
// Dispose the old binding and recreate a new binding
autoCompleteBinding.dispose();
autoCompleteBinding = TextFields.bindingAutoCompletion(TextField,List);
try this:
public void pushBills() {
ArrayList list = new ArrayList<>();
bills = new BillHeaderDao().FindAll();
for (int i = 0; i < bills.size(); i++) {
list.add(bills.get(i).getIdClient());
}
autoCompletionBinding.dispose();
autoCompletionBinding = TextFields.bindAutoCompletion(SearchBill, SuggestionProvider.create(list));
}
Using Autonomy WorkSite 8.5 SP2 SDK, I am attempting to programmicaly add a shortcut to another users My Matters which I have been told can be done by first subscribing to the other users My Matters, add the shortcut then unsubscribe.
I am therefore attempting to subscribe to another users My Matters however I am having issues with how to subscribe, with the below code I am able to locate the user's My Matters:
Dim objSFSP As IManSubscriptionFolderSearchParameters = oDms.CreateSubscriptionFolderSearchParameters
objSFSP.Add( imFolderAttributeID.imFolderOwner, sShortcutUser )
Dim objFolders As IManFolders = oMatters.FindRootSubscriptionFoldersNotSubscribedTo(oDatabaseList, objSFSP)
And from reading the COM Reference guide I should be able to subscribe to a users My Matters with the following code:
Dim objWorkArea As IManWorkArea = oSess.WorkArea
Dim oFolderShortcuts As IManSubscriptionFolderShortcuts = objWorkArea.SubscriptionFolder.SubFolders
Dim oFolderShortcut As IManFolderShortcut = oFolderShortcuts.AddNewSubscriptionFolderShortcutInheriting(objFolders)
The problem I am encountering is AddNewSubscriptionFolderShortcutInheriting() expects an object of the type IManSubScriptionFolder where FindRootSubscriptionFoldersNotSubscribedTo() returns a IManFolders object.
Can anyone point me in the direction of what I need to do to get an instance of the users My Matters as a IManSubscriptionFolder object?
Probably my response will be a bit late for you, but I hope that it will help anybody else who will have the same issue.
Answering your question, in order to get an instance of other users My Matters as a IManSubscriptionFolder object you just need to loop through the collection of objFolders and cast each folder to the IManSubScriptionFolder type.
Please find below my working solution:
ManDMS dms = new ManDMS();
string serverName = "dms.server.com";
IManSession session = dms.Sessions.Add(serverName);
string userID = "user";
string password = "password";
session.Login(userID, password);
ManStrings dblist = new ManStrings();
dblist.Add("TargetWsDbName");
IManSubscriptionFolderSearchParameters searchParams = ndms.CreateSubscriptionFolderSearchParameters();
string folderOwner = "AnotherUser";
searchParams.Add(imFolderAttributeID.imFolderOwner, folderOwner);
IManFolders nonSubscribedRootSubscriptionFolders = session.WorkArea.SubscriptionFolder.FindRootSubscriptionFoldersNotSubscribedTo(dblist, searchParams);
foreach (var folder in nonSubscribedRootSubscriptionFolders)
{
//another user's subscription folder
var subscriptionFolder = folder as IManSubscriptionFolder;
if (subscriptionFolder != null)
{
//Current user's subscription folder shortcuts
var subscriptionFolderShortcuts = session.WorkArea.SubscriptionFolder.SubFolders as IManSubscriptionFolderShortcuts;
if (subscriptionFolderShortcuts != null)
{
subscriptionFolderShortcuts.AddNewSubscriptionFolderShortcutInheriting(subscriptionFolder);
}
}
Please note that code from above was included for reference purpose only and it is not a production code.
I've got:
my-app
community-list
On attached, my-app gets the user and loads the app.user. In the meantime, community-list is attached (even before app.user is loaded) and so I haven't been able to get the user's starred communities yet. Therefore, the solution I'm working on is as follows.
In community-list.attached():
app.changes.listen((List<ChangeRecord> records) {
if (app.user != null) {
getUserStarredCommunities();
}
});
Elsewhere in community-list is said metho:
// This is triggered by an app.changes.listen.
void getUserStarredCommunities() {
// Determine if this user has starred the community.
communities.forEach((community) {
var starredCommunityRef = new db.Firebase(firebaseLocation + '/users/' + app.user.username + '/communities/' + community['id']);
starredCommunityRef.onValue.listen((e) {
if (e.snapshot.val() == null) {
community['userStarred'] = false;
} else {
community['userStarred'] = true;
}
});
});
}
Note that communities is an observable list in community-list:
#observable List communities = toObservable([]);
Which is initially populated in community-list.attached():
getCommunities() {
var f = new db.Firebase(firebaseLocation + '/communities');
var communityRef = f.limit(20);
communityRef.onChildAdded.listen((e) {
var community = e.snapshot.val();
// If no updated date, use the created date.
if (community['updatedDate'] == null) {
community['updatedDate'] = DateTime.parse(community['createdDate']);
}
// snapshot.name is Firebase's ID, i.e. "the name of the Firebase location"
// So we'll add that to our local item list.
community['id'] = e.snapshot.name();
// Insert each new community into the list.
communities.add(community);
// Sort the list by the item's updatedDate, then reverse it.
communities.sort((m1, m2) => m1["updatedDate"].compareTo(m2["updatedDate"]));
communities = communities.reversed.toList();
});
}
In summary, I load the list of communities even before I have a user, but once I have a user I want to update each community (Map) in the list of communities with the userStarred = true/false, which I then use in my community-list template.
Alas, it doesn't seem like the List updates. How do I achieve this?
This whole app.changes.listen business is expensive. What's the proper practice in a case like this, where an element is loaded before I load objects (like app.user) that will modify it in some way.
1)
toList() creates a copy of the list. You need to apply toObservable again to get an observable list.
communities = toObservable(communities.reversed.toList());
This also assigns a new list to communities which is covered by #observable.
I think it should trigger anyway
2) You update your communities explicitly. It shouldn't be necessary to listen for changes. You can call a method containing
if (app.user != null) {
getUserStarredCommunities();
}
explicitly each time you change the list.
You also call Firebase for each community when a change in communities occurs. I don't know Firebase but it seems you send a request to a server each time which is of course expensive.
You should remember for what user+community combination you already made the call and use the remembered result instead.
With app.changes.listen you listen to any updated of any #observable field in your component. If you have other observable fields beside communities this method might be called too often.
If you are only interested in changes to communities you should put this code into a method like
communitiesChanged(oldVal, newVal) {
if (app.user != null) {
getUserStarredCommunities();
}
}
but the better option is to not listen to changes and another method name and call it explicitly as state above anyways if possible.
I want to make something like the contact selection in OS 5.0 while composing message
For that I have made an autocompletefield with contacts as datasource. Now I want to add the user input, that is what he types into the drop down list which appears in autocompletefield so that if the contact is not available in the phonebook he can use the number.
Check this link: How to get the selected item as String in a Blackberry AutoCompleteField?
public void onSelect(Object selection, int type) {
super.onSelect(selection, type);
if(selection != null) {
String selectionAsString = getEditField().getText();
// Do whatever else you need to do with the String.
}
}
I m experiencing problem when I try to updating UI form
this is my ADO.NET Entity FrameWork model Entity Products with Column
with the following columns
ProductID int PK,
ProductName nvarchar(50),
ProductCode nvarchar(50),
ProductType nvarchar(50),
Description nvarchar(50),
CreateDate DateTime
and ProductPrice money
and I have 5 TextBoxes which contain
txtPName,txtDescription,txtCode,txtPrice,txtType,Datagrid to list all product from Database and btnupdate.and my textboxes are all binded correctly with datagrid, when I select any Item from the Datagrid it load the selectedItem to the all 5 txtboxes
so my problem started when I try to edit data from textboxes and click update button to update the the database.
this is my xaml code from UI
and xaml.cs for update button
private void btnEdit_Click(object sender, RoutedEventArgs e)
{
if (ProductList.SelectedIndex >= 0)
{
//get selected information first
Product newProduct = new Product();
newProduct.ProductName = txtName.Text.Trim();
newProduct.ProductPrice = (decimal)(12.00);//decimal.Parse(txtPrice.Text);
newProduct.ProductType = txtType.Text.Trim();
newProduct.ProductCode = txtProductCode.Text.Trim();
newProduct.Description = txtDescription.Text.Trim();
newProduct.CreateDate = DateTime.Now;//
Product product = ProductList.SelectedValue as Product;
//col.Remove(product);
//col.Add(newProduct);
db.SaveChanges();
MessageBox.Show("Row is updated successfully");
}
else
{
MessageBox.Show("Select");
}
}
the update code does not update the database.....
Please Guys I need help
from brianbk
email kagisobk#gmail.com
You don't create a new instance to update an existing entity, just apply the edits to the edited object, Entity Framework will track any changes you do to entities and will update the DB as appropriate when calling SaveChanges().
So just get the selected object as you did then transfer the new values to its properties and finally you call SaveChanges:
Product product = ProductList.SelectedValue as Product;
product.ProductName = txtName.Text.Trim();
product.ProductPrice = decimal.Parse(txtPrice.Text);
....
db.SaveChanges();
But the recommended and more efficient approach that you should be using is to use Data Binding to let WPF transfer the data between your entity and controls in both directions (Load/Update).
then in update button you just need to call SaveChanges().