【问题标题】:How to listen to change button in Google Wallet / Android Pay Fragment?如何收听 Google Wallet / Android Pay Fragment 中的更改按钮?
【发布时间】:2016-02-12 23:21:15
【问题描述】:

我正在开发一个移动 android 应用程序并使用 Android Pay/Google Wallet 从用户那里检索 CC 信息。我能够成功地让 GitHub 示例应用程序正常工作。

请看下图:

这里显示的屏幕似乎使用了一个动态屏蔽钱包片段。付款方式和送货地址以及更改按钮由 Android API 自动生成。

  1. 如何为这个片段定制我自己的 UI?
  2. 如何监听“CHANGE”按钮的 onClick 事件?
  3. 如何使用绿色的“Android Pay”标志(如图)?示例应用似乎仍在使用内置的“Google 电子钱包”徽标。

【问题讨论】:

    标签: android android-layout android-fragments android-activity android-pay


    【解决方案1】:

    我发现了如何在 MaskedWalletFragment 屏幕中使用 Android Pay 徽标。只需使用以下 API: https://developers.google.com/android/reference/com/google/android/gms/wallet/fragment/WalletFragmentStyle.LogoImageType.html#ANDROID_PAY

    关键是调用如下:

    setMaskedWalletDetailsLogoImageType(int)
    

    对 Android Pay 使用常量值 3。其余的已弃用。

    【讨论】:

      【解决方案2】:

      你用过方法

      1. .setBuyButtonAppearance(WALLET_APPEARANCE) 在 CkecoutActivity 中
      2. .setMaskedWalletDetailsLogoImageType(mWALLET_APPEARANCE) 在 ConfirmationActivity
      3. .useGoogleWallet() 在 FullWalletButton 中

      Android 钱包已弃用,就我而言,我这样做了:

      1. 检查设备是否支持 NFC(android pay 使用 NFC)
      2. 如果有 nfc 支持使用 android pay,如果没有我使用 android 钱包。

      首先在Constants.java中添加:

              //values to change buyapparence (android pay-wallet)
              public static final int GOOGLE_WALLET_CLASSIC=1;
              public static final int GOOGLE_WALLET_GRAYSCALE =2;
              public static final int GOOGLE_WALLET_MONOCHROME=3;
              public static final int ANDROID_PAY_DARK = 4;
              public static final int ANDROID_PAY_LIGHT=5;
              public static final int ANDROID_PAY_LIGHT_WITH_BORDER=6;
      

      然后在 utils 中用这个方法添加 nfcController.java:

              public boolean NFCsupport(){
                  boolean nfcSupport;
                  NfcManager manager = (NfcManager)mAppContext.getSystemService(Context.NFC_SERVICE);
                  NfcAdapter adapter = manager.getDefaultAdapter();
                  if (adapter != null && adapter.isEnabled()) {
                       nfcSupport=true;
                      //Yes NFC available
                  }else{
                      nfcSupport=false;
                      //Your device doesn't support NFC
                  }
                  return nfcSupport;
              }
      

      然后在你的 CheckoutActivity.java 或者当你有钱包实现时添加这个:

          if(nfcController.NFCsupport()){
                      //turn on nfc (other method in util nfcController.java)
                      nfcController.enableNfcPower(true);
                      //show nfc payment(android pay)
                      mWALLET_APPEARANCE=Constants.ANDROID_PAY_LIGHT;
                      createAndAddWalletFragment(mWALLET_APPEARANCE);
                      Log.d("nfc", "you have nfc support");
                  }else{
                      Log.d("nfc", "dont have nfc support");
                      //show not nfc payment(wallet)
                      mWALLET_APPEARANCE=Constants.GOOGLE_WALLET_CLASSIC;
                      createAndAddWalletFragment(mWALLET_APPEARANCE);
                  }
      

      在您的 createAndAddWalletFragment(int WALLET_APPEARANCE) 中更改外观标志:

              WalletFragmentStyle walletFragmentStyle = new WalletFragmentStyle()
              .setBuyButtonText(BuyButtonText.BUY_WITH_GOOGLE)
              .setBuyButtonAppearance(WALLET_APPEARANCE)
              .setBuyButtonWidth(WalletFragmentStyle.Dimension.MATCH_PARENT);
      

      其次,在intent中发送wallet_appareance:

                  intent.putExtra("wallet_appearance",mWALLET_APPEARANCE);
      

      并在您的确认活动中更新此函数以在 createAndAddWalletFragment() 中正确监听带有徽标的事件:

           WalletFragmentStyle walletFragmentStyle = new WalletFragmentStyle()
                  .setMaskedWalletDetailsLogoImageType(mWALLET_APPEARANCE)//from getintent
                  .setMaskedWalletDetailsTextAppearance(
                          R.style.BikestoreWalletFragmentDetailsTextAppearance)
                          .setMaskedWalletDetailsHeaderTextAppearance(
                                  R.style.BikestoreWalletFragmentDetailsHeaderTextAppearance)
                          .setMaskedWalletDetailsBackgroundColor(
                                  getResources().getColor(R.color.white))
                          .setMaskedWalletDetailsButtonBackgroundResource(
                                  R.drawable.bikestore_btn_default_holo_light);
      

      最后在 onCreate 方法中的 fullWalletconfirmationbutton.java 中不要忘记函数 useGoogleWallet 来创建和设置片段:

           // Set up an API client;
                  mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                          .addConnectionCallbacks(this)
                          .addOnConnectionFailedListener(this)
                          .setAccountName(accountName)
                          .addApi(Wallet.API, new Wallet.WalletOptions.Builder()
                                  .useGoogleWallet()
                                  .setEnvironment(Constants.WALLET_ENVIRONMENT)
                                  .setTheme(WalletConstants.THEME_HOLO_LIGHT)
                                  .build())
                          .build();
      

      你有安卓支付和安卓钱包支持。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-07
        • 1970-01-01
        • 1970-01-01
        • 2020-09-03
        • 2020-09-03
        相关资源
        最近更新 更多