"Capacitor android plugin example" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "Capacitor android plugin example" answered properly. Developers are finding an appropriate answer about Capacitor android plugin example related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like Capacitor android plugin example. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on Capacitor android plugin example. 

Capacitor android plugin example

By Xanthous XenomorphXanthous Xenomorph on May 02, 2021
package com.devdactic.contacts;
 
import android.Manifest;
import android.content.ContentResolver;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.util.Log;
 
import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
 
import org.json.JSONArray;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
 
@NativePlugin(
        requestCodes={ContactsPlugin.REQUEST_CONTACTS}
)
public class ContactsPlugin extends Plugin {
    protected static final int REQUEST_CONTACTS = 12345; // Unique request code
 
    @PluginMethod()
    public void getContacts(PluginCall call) {
        String value = call.getString("filter");
        // Filter based on the value if want
 
        saveCall(call);
        pluginRequestPermission(Manifest.permission.READ_CONTACTS, REQUEST_CONTACTS);
    }
 
    @Override
    protected void handleRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.handleRequestPermissionsResult(requestCode, permissions, grantResults);
 
 
        PluginCall savedCall = getSavedCall();
        if (savedCall == null) {
            Log.d("Test", "No stored plugin call for permissions request result");
            return;
        }
 
        for(int result : grantResults) {
            if (result == PackageManager.PERMISSION_DENIED) {
                Log.d("Test", "User denied permission");
                return;
            }
        }
 
        if (requestCode == REQUEST_CONTACTS) {
            // We got the permission!
            loadContacts(savedCall);
        }
    }
 
    void loadContacts(PluginCall call) {
        ArrayList<Map> contactList = new ArrayList<>();
        ContentResolver cr = this.getContext().getContentResolver();
 
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);
        if ((cur != null ? cur.getCount() : 0) > 0) {
            while (cur != null && cur.moveToNext()) {
                Map<String,String> map =  new HashMap<String, String>();
 
                String id = cur.getString(
                        cur.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cur.getString(cur.getColumnIndex(
                        ContactsContract.Contacts.DISPLAY_NAME));
 
                map.put("firstName", name);
                map.put("lastName", "");
 
                String contactNumber = "";
 
                if (cur.getInt(cur.getColumnIndex( ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
                    Cursor pCur = cr.query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
                            new String[]{id}, null);
                    pCur.moveToFirst();
                    contactNumber = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    Log.i("phoneNUmber", "The phone number is "+ contactNumber);
                }
                map.put("telephone", contactNumber);
                contactList.add(map);
            }
        }
        if (cur != null) {
            cur.close();
        }
 
        JSONArray jsonArray = new JSONArray(contactList);
        JSObject ret = new JSObject();
        ret.put("results", jsonArray);
        call.success(ret);
    }
}

Source: devdactic.com

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on Capacitor android plugin example can get a collection of related answers to their query. Programmers need to enter their query on Capacitor android plugin example related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Capacitor android plugin example for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of Capacitor android plugin example while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "Capacitor android plugin example". Visit this developer's friendly online web community, CodeProZone, and get your queries like Capacitor android plugin example resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "Capacitor android plugin example"

View All Whatever queries

Whatever queries related to "Capacitor android plugin example"

Capacitor android plugin example capacitor build android without android studio ionic capacitor build android apk command fail on missing web xml plugin to add in spring-boot-maven-plugin ionic capacitor splash screen cordova resources keyboard capacitor npm for capacitor local notifications capacitor ask for file system permissions android studio not open missing essentian plugin import tools example print(tools example.roll_dice(5)) get incoming call number android example firestore geopoint query example in android android google places autocomplete example introduction to firebase database android kotlin example flutter requires android sdk 29 and the android buildtools 28.0.3 Execution failed for task ':app:processDebugResources'. > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > Android resource linking failed android convert sensorEvent timestamp into unix timestamp android get jenkins plugin list best plugin in wordpress for SEO url params wordpress plugin maven site plugin 3.3 doxia class not found delayed exchange plugin enable infinite scroll wordpress without plugin maven-dependency-plugin eclipse delete plugin how to make a plugin wait on enabke updated the mail id in sucuri security plugin Cordova SMS Plugin project download question and answer woocommerce product page without plugin grafana grouped bar chart plugin file type plugin indentation vim babel minify plugin vim display key press plugin wordpress plugin to update links inside iframe create plugin in craft cms 3 gst-plugin-scan 100 cpu copy-globs-webpack-plugin compilation.fileDependencies.has is not a function bin/cake plugin No such file or directory: 'pkg-static' Partial plugin destroyed ERROR in Please check your GenerateSW plugin configuration: "glob Patterns" is not a supported parameter. jinja2 plugin for pycharm speed index wp plugin Self hosted Auto update Custom WP Plugin or Theme - AKA Personal Wordpress Update Repository Performing a build. Maven plugin allow you to set the specific version of the artifact to be built without manually modifying the pom.xml file: jsweet-maven-plugin logstash-plugin undefined method `headers' Plugin header babel-plugin-transform-react-inline-elements vue slider plugin clang pass argument to plugin irs range plugin gatsby-plugin-react-helmet-canonical-urls Reinstalling SpaceVim Plugin @techiediaries/vue-cli-plugin-bootstrap npm Cordova Plugin InAppBrowser sample How to enable sand dupe in papermc or plugin no invulnerability on join plugin Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin'] site:stackoverflow.com Plugin [id: 'com.bmuschko.tomcat'] was not found in any of the following sources: gatsby-plugin-notifications failed to initialize plugin et_quicktags wordpress No valid crumb was included in request for /plugin/swarm/create Slave by swarm.node. Returning 403 adobe analytics time parting plugin pull request template example flutter toggle button example PageView Flutter Example example website homepage kubectl describe configmap example vue-pdf example $anchorscroll example ionic storage example checkboxcontrolvalueaccessor example webgl cube example uipath data table print index example secure copy example maximum path sum input output example setters and getter best example spark.read.option(header,inferschema) .csv example phonegap admob example log4j example example of defibrillation regression test with example retrieve dynamod db streams example document.getElementsByClassName('green Border example')[0] .style.border="10px solid green"; menu macro twig example Political parties are a necessary condition for a democracy.’ Analyze the statement with example 8086 example hello world google finance INDEX CSI example syslog message format example oop encapsulation example definition of ready example scrum a example for cunfuision matrix example of a min heap antlr 4 grammar example swagger parameters multiple query example For example, there are n=7 socks with colors ar=[1,2,1,2,1,3,2]. There is one pair of color 1 and one of color 2. mongoclientoptions example gdal_polygonize example org-capture template example python list comprehension with filter example @remoteaction example in salesforce scipy cdf example readwritelock example ItemMeta method example roo-xls example pterodactyl curl request example python list comprehension with filter example 2 sas guide sleep function example pdfbox print example krakend example completablefuture async example document.getelementbyid( timeend ).value example 2020 add tr td emmet in vscode example singleton design pattern example doubly linked list example docker swagger ui example plotly mesh3d example target encoder sklearn example Spring Data Elasticsearch update document example gettimeofday c example milliseconds chsarp dict example google_maps_flutter web example scenario testing example Object example nightmare node example 2DM example code kafka docker compose example esp8266 wifi example runif in r example sinon spy function example roundingmode.half_down example C# OOP example example of full stack snook example fork example questions counter load byte mips example asyncio queue example xml schema example xargs example example website taggeddocument gensim example example ramda pipe kotlin recyclerview model in example Write Number in Expanded Form You will be given a number and you will need to return it as a string in Expanded Form. For example: uialertcontroller example objective Code Answer conditions example in sap alert notification navigation Preload example workbox OnCircuitClosedAsync example pageable unpaged example Example 4-2 Aluminum cube deformation, implicit method (file: im01.k) logstash-filter-math example UICollectionViewCell awakefromnib example windows docker compose rabbitmq example onbackpressed android android recyclerview bottom padding view binding in android what is error make sure you have android development environment set up findview by id in android install android sdk placeholder android studio enable view binding android android process is waiting for debugger to attach spinner android android textview multiple font size no target device found android studio android navigation drawer menu item color ionic getting automatic disable dark mode on android table layout android studio android.content.res.Resources$NotFoundException: String resource ID #0x0 download android studio button style android studio picasso android not working snackbar gravity android Could not initialize class com.android.sdklib.repository.AndroidSdkHandler set dart sdk from android studio android translate animation values A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade > java.lang.OutOfMemoryError (no error message) chnage hex color to int color in android clean build in android studio dexter android atic interface methods are only supported starting with Android N (--min-api 24): void butterknife.Unbinder.lambda$static$0()] android sdk location mac android studio string new line android studio turn off screen rotation enable vector drawable android android foreach how to get app package and app activity in android android moshi retrofit android searchview in toolbar hyperlink in android how to use font awesome icons in android chrome inspect android http/1.1 404 not found how to check and uncheck single radio button in android making Log in android viewmodelscope android android how to get width of widows android picasso proguard android disable app admin in adb

Browse Other Code Languages

CodeProZone