Storing photo in user's contacts using the Cordova Contacts extension

Struggling to save an image to the user’s contacts using the Cordova Contacts plugin on Android. Take a look at my code snippet below:

var contact = navigator.contacts.create();

// data.photo contains a valid base64-encoded string.
contact.photos[0] = {
  "type": "base64",
  "value": data.photo
};

contact.save(function() {
  alert(“Contact saved.”);
}

The above code functions flawlessly on iOS, however, I'm encountering issues saving an image on Android regardless of trying various methods. The data.photo is confirmed as a valid base64-encoded string that displays as an image when inputted into a URL bar. Any suggestions or guidance?

Answer №1

This issue revolves around the inability to save data in base64 format.

In the 'ContactAccessorSdk5.java' file located at 'Platform/android/build/src/org/apache/cordova/contacts/', there is no support for base64 type.

Image data in base64 format typically begins with 'data:'. To enable saving image data in base64, you can make modifications to the getPathFromUri(String path) method within the 'ContactAccessorSdk5.java' file.

For more information, you can visit the PhoneGap forum discussion here or check out my GitHub repository here.

By accessing the code in these resources, you will find detailed instructions on resolving this issue.

private InputStream getPathFromUri(String path) throws IOException {
    // Implementation details here
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Could you please explain the distinctions among onLoad, onDomready, No wrap - in <head>, and No wrap - in <body>?

When it comes to editing my code, I rely on JSFiddle. However, I have noticed that in certain instances when running JavaScript or jQuery, the code only works if I choose "No wrap - <head>" or "No wrap - <body>". CLICK HERE FOR THE JSFIDDLE EX ...

Warning: android.app.Notification$Builder Logs in Logcat

Recently integrated Google Play Services into my app and encountered these warnings: 12-18 20:31:50.320: I/dalvikvm(8579): Could not find method android.app.Notification$Builder.setPriority, referenced from method com.google.android.gms.common.GooglePlayS ...

Can a click listener be added to a CSS box similar to this one in my scenario?

Exploring React and Javascript, I've been working on a project in Codesandbox. I attempted to add a "click to open" functionality that triggers a popup, but it seems like CSS and click interactions don't always play nicely together. In the proje ...

Changing the background color of radio buttons using Chrome and the power of WebGL<script>canvas</script>

When using the Three.js WebGL renderer, I noticed that radio buttons have white backgrounds, but this issue only seems to occur in Chrome. If you want to see the problem for yourself, check out this fiddle: http://jsfiddle.net/5pL8v/328/ Does anyone know ...

How to eliminate relative path from a URL using JavaScript/jQuery

Currently, I am utilizing jQuery to locate and fetch various img src's from the DOM. However, these src paths are in relative format as shown below: src="../../../../../dynamic/eshop/product_images/thumbnail_cache/366x366/042-1392_13760000.1.jpg" My ...

Error: AngularJS is experiencing an injector module error that has not been caught

I have set up an Angular boilerplate that includes various elements such as meta tags, CDN links, and script tags. However, I am encountering a persistent error in my console and cannot figure out the root cause of it. https://i.stack.imgur.com/qPGby.png ...

Preventing Element Reload in Django Using AJAX Across Multiple Templates

NOTE: Updated base.html and refined title UPDATE 2: An example of what I'm referring to is the ticker showing x y z, then transitioning to a, b, c, and so forth. How can I maintain the position of the ticker when navigating pages so that if it's ...

Is there a way I can retrieve the appended link text upon clicking?

Hello everyone! I have successfully created my own jQuery/JavaScript auto complete search suggestions div. I have implemented a feature where it pulls in an XML dictionary full of words and uses regular expressions to suggest matches based on user input. H ...

Troubleshooting the Alignment Issue in Angular Material Expansion Panel Header

I have implemented an Angular 14 Material Expansion Panel as shown in the code snippet below... <mat-nav-list> <a mat-list-item role="listitem" class="list-item-setting" id="emailTemplatesId" matTooltipPosition=&quo ...

Passing "this" to the context provider value in React

While experimenting with the useContext in a class component, I decided to create a basic React (Next.js) application. The app consists of a single button that invokes a function in the context to update the state and trigger a re-render of the home compon ...

Replace the checkbox display heading with a text box in the designated area

I'm new to using kendo ui Currently, I am attempting to show a text box in the first column header. Instead of the checkboxDisplay heading, I want to replace it with a text box. Could someone please provide guidance on how to resolve this issue? Here ...

The issue with Ajax success not functioning properly within nested .ajax calls

I encountered an issue with my nested ajax functions. The success code is triggered in the first ajax request (url: "get_hours.php"), but not in the second case (url: "send.php"). The code within "send.php" is executed correct ...

Guide on enabling users to input slide number and URL address to load content using Ajax

Is there a way to customize the number of slides in a slider and choose which content is loaded into each slide using AJAX calls in jQuery? Currently, my slider uses the jQuery .load() method to dynamically load content into each slide when it becomes vis ...

Is there a way to search for a specific item within a nested array?

I have 2 arrays within an array, each containing objects. How can I locate the object with the name "Sneijder"? const players = [ [ { id: 1, name: "Hagi", }, { id: 2, name: "Carlos", }, ], [ { id: 3 ...

Error encountered in Android socket-based chat program

When I input texts into the EditText in the Emulator's application and click the button, the texts are not displaying in the TextView. I'm not sure what is causing this issue - could it be a problem with the server or the client? Below is the An ...

Why does json_encode() work for one string and fail for another?

UPDATE: Resolved the issue. Initially, someone left a comment with a solution that was later deleted. Interestingly, simply adding semi-colons after the two json_encode lines fixed the problem. I'm still puzzled as to why string1 worked without a clo ...

manipulating session variables with javascript ajax and php

I'm struggling with setting and retrieving session variables using JavaScript code that calls PHP functions via AJAX. I want to access the returned session field in my JavaScript, but nothing seems to be working. Can someone take a look at my code and ...

Error: The requested address is currently in use by Node.js and Express

Every time I try to save my files using nodemon, an error pops up with the following message: events.js:292 [0] throw er; // Unhandled 'error' event [0] ^ [0] [0] Error: listen EADDRINUSE: address already in use :::9000 [0] at Se ...

Flatten information from an object containing multiple objects within an array

In my current project using Vue, I am making an API call to retrieve data from my Laravel backend (nova). The returned data is structured in the following way. The data consists of an array, which contains arrays of objects. Each array represents a record ...

TypeScript and the Safety of Curried Functions

What is the safest way to type curried functions in typescript? Especially when working with the following example interface Prop { <T, K extends keyof T>(name: K, object: T): T[K]; <K>(name: K): <T>(object: T) => /* ?? */; ...