你用过方法
-
.setBuyButtonAppearance(WALLET_APPEARANCE) 在 CkecoutActivity 中
-
.setMaskedWalletDetailsLogoImageType(mWALLET_APPEARANCE) 在 ConfirmationActivity
-
.useGoogleWallet() 在 FullWalletButton 中
Android 钱包已弃用,就我而言,我这样做了:
- 检查设备是否支持 NFC(android pay 使用 NFC)
- 如果有 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();
你有安卓支付和安卓钱包支持。