termux / termux/termux-api

Feature wish: RawContacts read and write

Open
#766 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.3k
Forks
920
PR merge metrics
No merged PRs in 30d

Description

Feature description

Please consider adding the feature to allow:

  • dumping the complete RawContacts table and its corresponding Data table;
  • inserting and deleting lines into/from these tables.

Reference implementation

I have started my own app, to be called from Termux with am start -n $app, it is in very early stage, but it can already dump the RawContacts database:

    public void log_all_raw_contacts() {
        Cursor cursor = getContentResolver().query(
            ContactsContract.RawContacts.CONTENT_URI,
            null /* all columns TODO */,
            null, null, null
        );
        while (cursor.moveToNext()) {
            String name = cursor.getString(0);
            warn("raw_contact\n");
            for (int i = 0; i < cursor.getColumnCount(); i++)
                warn("  %s = \"%s\"\n", cursor.getColumnName(i), cursor.getString(i));
        }
    }

and an AI did for me the insertion, which happens to work:

    public void add_contact_test() {
        ContentResolver resolver = getContentResolver();
        ArrayList<ContentProviderOperation> ops = new ArrayList<>();

        // 1. Insert a new raw contact
        ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
            .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
            .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
            .build());

        // 2. Insert the display name "Toto"
        ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, "Toto")
            .build());

        // 3. Insert the mobile phone number "42 17 19"
        ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, "42 17 19")
            .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
            .build());

        // Apply the batch
        try {
            resolver.applyBatch(ContactsContract.AUTHORITY, ops);
        } catch (RemoteException | OperationApplicationException e) {
            e.printStackTrace();
        }
    }

Thanks in advance.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing existing Termux API command implementations and the Android ContactsContract.RawContacts and ContactsContract.Data APIs shown in the reference code. The feature would need a defined command interface for dumping both tables and inserting or deleting rows, with behavior and safety expectations clarified before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
cli, mobile-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.