Coder Social home page Coder Social logo

Comments (10)

xUnholy avatar xUnholy commented on June 15, 2024

Interesting. I'll have a look in the morning If I get a spare minute or two, feel free to fork and try debug or improve yourself, always happy to have more people contribute

from cordova-device-accounts-v2.

endareBrock avatar endareBrock commented on June 15, 2024

I think the 'only google' is straightforward
image

android api says:
an optional string array of account types., i think leaving the 'com.google' out will give all the options

The not returning problem is maybe related to the fact there is no return value ? and the other methods do.

from cordova-device-accounts-v2.

endareBrock avatar endareBrock commented on June 15, 2024

Can confirm that replacing new String[]{"com.google"} by null, lets you choose between all your accounts. Right now i am struggling with the second issue

from cordova-device-accounts-v2.

endareBrock avatar endareBrock commented on June 15, 2024

I almost figured it out.
You need to set the callbackContext locally and do following

  private void getPermissions() {
    AccountManager manager = AccountManager.get(cordova.getActivity().getApplicationContext());
    Intent accountIntent = manager.newChooseAccountIntent(null, null, null, null, null, null, null);
    cordova.setActivityResultCallback(this);
    cordova.getActivity().startActivityForResult(accountIntent, VISIBILITY_VISIBLE);
  }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent intent){
    if(requestCode == VISIBILITY_VISIBLE && this.callbackContext != null){
        this.callbackContext.success("Success");
    } else {
        this.callbackContext.error("Invalid requestCode: " + requestCode);
    }
  }

It fires the success callback but reaches the reject of the app.

from cordova-device-accounts-v2.

endareBrock avatar endareBrock commented on June 15, 2024

i managed to write this but it still needs improvements.
Would you mind taking a look ? My Android knowledge is far, far away.

  private void getPermissions(String type) {
    AccountManager manager = AccountManager.get(cordova.getActivity().getApplicationContext());
    Intent accountIntent = manager.newChooseAccountIntent(null, null, new String[]{type}, null, null, null, null);
    cordova.setActivityResultCallback(this);
    cordova.getActivity().startActivityForResult(accountIntent, VISIBILITY_VISIBLE);
  }
  private void getPermissions() {
      AccountManager manager = AccountManager.get(cordova.getActivity().getApplicationContext());
      Intent accountIntent = manager.newChooseAccountIntent(null, null, null, null, null, null, null);
      cordova.setActivityResultCallback(this);
      cordova.getActivity().startActivityForResult(accountIntent, VISIBILITY_VISIBLE);
    }

  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data){
    if(requestCode == VISIBILITY_VISIBLE && this.callbackContext != null){
         this.callbackContext.success("Success " + data.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE +" "+ data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME)));
    } else {
         this.callbackContext.error("Invalid requestCode: " + requestCode);
    }
  }

This would have the option to give a type argument (instead of the "google.com")
image

from cordova-device-accounts-v2.

xUnholy avatar xUnholy commented on June 15, 2024

Separating the account type and callback issues #11

from cordova-device-accounts-v2.

xUnholy avatar xUnholy commented on June 15, 2024

This would be much easier to review in a pull request - additionally, I think the getPermissions() function should actually return all accounts, then the type should be handled by the getAccounts() function which already handles the type to receive.

from cordova-device-accounts-v2.

xUnholy avatar xUnholy commented on June 15, 2024

I've been working on making an easy usage guide for this plugin with an ionic application. Check it out here, perhaps we can add this to the examples once we also get this working. https://github.com/xUnholy/cordova-device-accounts-example

from cordova-device-accounts-v2.

xUnholy avatar xUnholy commented on June 15, 2024

Please review and test the following - I've used some of your logic and tweaked it to solve the underlying issue with the promise resolving incorrectly which was a bug. Effectively the promise would be rejected even though internally it resolved.

from cordova-device-accounts-v2.

xUnholy avatar xUnholy commented on June 15, 2024

Pull request can be reviewed here - #12

from cordova-device-accounts-v2.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.