我正在开发移动Android应用,并使用Android Pay / Google Wallet从用户检索CC信息。我能够成功地使GitHub示例应用程序正常工作。
此处显示的屏幕似乎使用动态蒙版钱包片段。付款方式和送货地址以及更改按钮由Android API自动生成。
答案 0 :(得分:0)
我发现了如何在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的常量值。其余的已被弃用。
答案 1 :(得分:-1)
你已经使用了方法
.setBuyButtonAppearance(WALLET_APPEARANCE)
.setMaskedWalletDetailsLogoImageType(mWALLET_APPEARANCE)
.useGoogleWallet()
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);
其次,发送了wallet_appareance in intent:
intent.putExtra("wallet_appearance",mWALLET_APPEARANCE);
并在您的confirmationActivity中更新此功能,以便在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中,不要忘记使用googleWallet函数来创建和设置片段:
// 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钱包支持。