@dderevjanik/termux-api
Version:
This library allows you to interact with your Android device from Node.js using termux-api
37 lines (34 loc) • 851 B
text/typescript
import { exec } from "child_process";
export interface Contact {
/**
* The name of the contact
* @example "John Doe"
*/
name: string;
/**
* The number of the contact
* @example "+421910123456" or "0910123456" or "4ka"
*/
number: string;
}
/**
* List all contacts
*
* **Requires permission:** `android.permission.READ_CONTACTS`
*/
export async function contactList(): Promise<Contact[]> {
return new Promise<Contact[]>((resolve, reject) => {
const command = "termux-contact-list";
exec(command, (error, stdout, stderr) => {
if (error) {
return reject(`Error: ${error.message}`);
}
if (stderr) {
return reject(`Error: ${stderr}`);
}
const output = stdout.trim();
const contacts: Contact[] = JSON.parse(output);
return resolve(contacts);
});
});
}