Forum Stats

  • 3,815,693 Users
  • 2,259,068 Discussions
  • 7,893,208 Comments

Discussions

ADF Mobile: creating contact on device only after user selects ALLOW button

TreeStrepek
TreeStrepek Member Posts: 260
edited Jul 1, 2014 6:31PM in JDeveloper and ADF

My app allows users to quickly and easily add contacts on their IOS phone.  I need help capturing the "DON'T ALLOW" button click.

Background:

When adding a contact on the users device phoneGap prompts the user "Allow theApp to Access Contacts?".  After this alert is shown the user must select either "Allow" or "Don't Allow".  Of course if the user selects "Allow" my code runs perfectly.

However, if the user selects "Don't Allow" I am not able to capture that selection and process accordingly. 

Here's the line of code that processes the newContact for that app user.

Contact newContact = device.createContact(contact);

     where "contact" has been preset with user data;

Would you offer your expert opinion on how to proceed please?

Many Thanks!

Tree Strepek

Tagged:

Best Answer

Answers

  • dvohra21
    dvohra21 Member Posts: 14,494 Gold Crown

    If one of the two has to be selected, use the ! (complement) of the value returned with Allow to process for Don't Allow.

    For example, if Allow returns a value boolean true, if the value is not true implies Don't Allow has been selected.

    if (allow!=true)

    Implies Don't Allow is selected.

  • TreeStrepek
    TreeStrepek Member Posts: 260

    Thank you for that insight Mystery Man "dvohra21".   LOL. 

    I have a detailed implementation question=> what is the syntax to capture the value(whether allow or !allow) I am trying to find how to capture the user's selection.  Phonegap takes control for a brief second.  It is outside the control of my app for a  moment.   In this period of time the User is prompted if they agree to "allow access".

    How do I access the result returned by phonegap?  Is the Contact newContact = device.createContact(contact); call automatically populating a callback method?  Or setting a variable somewhere I can access. If so can you offer some direction on where to look for the details? 

    Contact newContact = device.createContact(contact);  <- the command that calls Phonegap to interact with the device's OS.

    Thank You for all your help!

    Tree Strepek

  • dvohra21
    dvohra21 Member Posts: 14,494 Gold Crown

    Refer

    Oracle ADF Mobile Decoded: ADF Mobile: Capture User Response to Alert Popup

    which makes use of AdfmfContainerUtilities.invokeContainerJavaScriptFunction to capture user response.

  • TreeStrepek
    TreeStrepek Member Posts: 260

    Hey dvohra21:

    I love it that you're referencing my blog entry on this subject.  I created that blog as I was trying to decode how to use JavaScript call back methods in AdfmfContainerUtilities.  A technique I tried and dismissed as a solution.  (I am still working to clarify the syntax on Javascript call back methods).

    But my question here specifically refers to capturing the result of the Phonegap UI alert "Allow App to Access Contacts?".  2 buttons are displayed.  "Allow", "Don't Allow". If the user always selects "Allow" my code works as designed.  However, I am coding for the other scenario=> the user selects "Don't Allow".

    My Essential Question: How do I access the users selection to the Phonegap alert?   This seems to happen outside ADF Mobile's control(as a blocking call to Phonegap)

    Is there a return value I can access?  Is it like the Javascript scenario(in AdfmfContainerUtilities), in which, there is a callBack method I can query for the results?

    It seems if the user selects "Don't Allow" the contact should not get added to their device's contact list.  && I need to reset the phone gap parameter, so that same user gets prompted next time they want to add a contact.  (right now the user's selection is final)

    I appreciate you sharing your knowledge with me!

    Tree Strepek

  • dvohra21
    dvohra21 Member Posts: 14,494 Gold Crown

    Is there a return value I can access?  Is it like the Javascript scenario(in AdfmfContainerUtilities), in which, there is a callBack method I can query for the results?


    All notifications provide a callback function.

    notification.confirm

    confirmCallback: Callback to invoke with index of button pressed (1, 2, or 3) or when the dialog is dismissed without a button press (0).

    notification.alert

    alertCallback: Callback to invoke when alert dialog is dismissed. (Function)

    notification.prompt

    promptCallback: Callback to invoke when a button is pressed. (Function)

    http://docs.phonegap.com/en/3.0.0/cordova_notification_notification.md.html

  • Mrityunjay Kant
    Mrityunjay Kant Member Posts: 2 Red Ribbon

    I believe the correct issue is here that if the user disallows access to contacts then how do we detect that? The prompt in question regarding access to Contacts is displayed by iOS and it's response cannot be captured similar to an alert response.

    IS there a call or way we can hook into PhoneGap to discover if the user has disallowed access to contacts before performing contact related operations? This way we can diplay a message asking user to first enale access to contacts rather than attempt the operation and fail.

  • dvohra21
    dvohra21 Member Posts: 14,494 Gold Crown
    Answer ✓

    The permissions for iOS are set in config.xml.

    <plugin name="Contacts" value="CDVContacts" />

    https://github.com/apache/cordova-plugin-contacts/blob/master/src/ios/CDVContacts.h

  • TreeStrepek
    TreeStrepek Member Posts: 260

    That's right.  Thank you for that clarification.

  • TreeStrepek
    TreeStrepek Member Posts: 260

    Phonegap interaction (including user response) has been brought into  MAF. 

This discussion has been closed.