我使用'添加保存到Android Pay到您的应用程序'建立会员卡'使用我的应用程序我引用他们的代码片段,但它在我的项目中不起作用。
错误 - >无法在编译时解析方法newBuilder()
以下是代码段
// Define Points
LoyaltyPoints points = LoyaltyPoints.newBuilder()
.setLabel("Points")
.setType("points")
.setBalance(LoyaltyPointsBalance.newBuilder().setString("500").build()).build();
// Define Text Module Data
List textModulesData = new ArrayList();
TextModuleData textModuleData = new TextModuleData("Jane's Baconrista Rewards", "Save more at your local Mountain View store Jane. You get 1 bacon fat latte for every 5 coffees purchased. Also just for you, 10% off all pastries in the Mountain View store.");
textModulesData.add(textModuleData);
// Define Links Module Data
List uris = new ArrayList();
UriData uri1 = new UriData("http://www.baconrista.com/myaccount?id=1234567890","My Baconrista Account");
uris.add(uri1);
List imageUris = new ArrayList();
UriData uri2 = new UriData("http://examplesite/images/exampleimage2.jpg", "Image Description");
imageUris.add(uri2);
// Define Info Module
List row0cols = new ArrayList();
LabelValue row0col0 = new LabelValue("Next Reward in","2 coffees");
LabelValue row0col1 = new LabelValue("Member Since", "01/15/2013");
row0cols.add(row0col0);
row0cols.add(row0col1);
List row1cols = new ArrayList();
LabelValue row1col0 = new LabelValue("Local Store", "Mountain View");
row1cols.add(row1col0);
List rows = new ArrayList();
LabelValueRow row0 = LabelValueRow.newBuilder().setHexBackgroundColor("#922635")
.setHexFontColor("#F8EDC1").addColumns(row0cols).build();
LabelValueRow row1 = LabelValueRow.newBuilder().setHexBackgroundColor("#922635")
.setHexFontColor("#F8EDC1").addColumns(row1cols).build();
rows.add(row0);
rows.add(row1);
// Define general messages
List messages = new ArrayList();
WalletObjectMessage message = WalletObjectMessage.newBuilder()
.setHeader("Hi Jane!")
.setBody("Thanks for joining our program. Show this message to " +
"our barista for your first free coffee on us!")
.setImageUri(
new UriData("http://examplesite/images/exampleimage1.jpg",""))
.setActionUri(new UriData("http://baconrista.com",""))
.build();
messages.add(message);
// Define Geolocations
LatLng location = new LatLng(37.422601, -122.085286);
List locations = new ArrayList();
locations.add(location);
// Build and Return New LoyaltyWalletObject
return LoyaltyWalletObject.newBuilder()
.setClassId("2967745143867465930.LoyaltyClass")
.setId("2967745143867465930.LoyaltyObject")
.setState(WalletObjectsConstants.State.ACTIVE)
.setAccountId("1234567890")
.setAccountName("Jane Doe")
.setIssuerName("Baconrista")
.setProgramName("Baconrista Rewards")
.setBarcodeType("qrCode")
.setBarcodeValue("28343E3")
.setBarcodeAlternateText("12345")
.setBarcodeLabel("User Id")
.setLoyaltyPoints(points)
.addTextModulesData(textModulesData)
.addLinksModuleDataUris(uris)
.setInfoModuleDataHexFontColor("#F8EDC1")
.setInfoModuleDataHexBackgroundColor("#442905")
.setInfoModuleDataShowLastUpdateTime(true)
.addInfoModuleDataLabelValueRows(rows)
.addImageModuleDataMainImageUris(imageUris)
.addMessages(messages)
.addLocations(locations)
.build();
参考文档链接: https://developers.google.com/save-to-android-pay/guides/android/add-button-to-your-app