3

我正在開發一款手機安卓應用,並使用Android Pay/Google Wallet從用戶那裏檢索CC信息。我能夠成功地讓GitHub示例應用程序工作。如何收聽Google電子錢包/ Android Pay片段中的更改按鈕?

請參見下圖: enter image description here

看來,這裏顯示的屏幕採用了動態屏蔽錢包片段。付款方式和送貨地址以及更改按鈕是由Android API自動生成的。

  1. 我該如何爲這個片段定製我自己的UI?
  2. 如何收聽「更改」按鈕的onClick事件?
  3. 如何以綠色(在圖像中)使用「Android Pay」徽標?示例應用似乎仍然使用內置的「Google電子錢包」徽標。

回答

-1

U的使用方法

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

Android的錢包已被棄用,在我來說,我這樣做:

  1. 檢查ID設備有NFC支持(安卓支付使用NFC)
  2. 如果有nfc支持使用android支付,如果沒有我使用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或當你有錢包FPGA實現補充一點:

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); 

其次,發送的意圖wallet_appareance:

  intent.putExtra("wallet_appearance",mWALLET_APPEARANCE); 

並在您的confirmationActivity中更新此功能,以便在createAndAddWalletFragment()中正確地使用徽標來聆聽事件:

在onCreate方法您fullWalletconfirmationbutton.java
 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); 

最後不要忘了功能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(); 

,你必須付出的Android和Android的錢包支持。