//静默登陆
private void silentlogin() {
AccountAuthParams params = new AccountAuthParamsHelper().createParams();
AccountAuthService service = AccountAuthManager.getService(this, params);
service.silentSignIn().addOnSuccessListener(new OnSuccessListener<AuthAccount>() {
@Override
public void onSuccess(AuthAccount authAccount) {
System.out.println(authAccount.getDisplayName());
}
});
}
//idtoke登陆
private void idtokenlogin() {
AccountAuthParams params = new AccountAuthParamsHelper().setIdToken().createParams();
AccountAuthService service = AccountAuthManager.getService(this, params);
startActivityForResult(service.getSignInIntent(),5555);
if (requestCode==5555){
Task<AuthAccount> task = AccountAuthManager.parseAuthResultFromIntent(data);
task.addOnSuccessListener(new OnSuccessListener<AuthAccount>() {
@Override
public void onSuccess(AuthAccount authAccount) {
System.out.println("登录成功!!!!!!");
System.out.println(authAccount.getIdToken());
}
});
}
}
//code登陆
private void AClogin() {
AccountAuthParams params = new AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM).setAuthorizationCode().createParams();
AccountAuthService service = AccountAuthManager.getService(this, params);
startActivityForResult(service.getSignInIntent(),3333);
if (requestCode==3333){
Task<AuthAccount> authAccountTask = AccountAuthManager.parseAuthResultFromIntent(data);
authAccountTask.addOnSuccessListener(new OnSuccessListener<AuthAccount>() {
@Override
public void onSuccess(AuthAccount authAccount) {
System.out.println("登录成功!!!!");
System.out.println(authAccount.getAuthorizationCode());
}
});
}
//检查是否购买
private void buy() {
Task<IsEnvReadyResult> envReady = Iap.getIapClient(this).isEnvReady();
envReady.addOnSuccessListener(new OnSuccessListener<IsEnvReadyResult>() {
@Override
public void onSuccess(IsEnvReadyResult isEnvReadyResult) {
System.out.println(isEnvReadyResult.getCarrierId());
System.out.println("ok");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof IapApiException){
IapApiException apiException = (IapApiException) e;
Status status = apiException.getStatus();
if (status.getStatusCode()==OrderStatusCode.ORDER_HWID_NOT_LOGIN){
if (status.hasResolution()) {
try {
status.startResolutionForResult(MainActivity2.this,1111);
} catch (IntentSender.SendIntentException sendIntentException) {
sendIntentException.printStackTrace();
}
}
}
}
}
});
}
//展示商品信息
private void dilayProduct() {
List<String> strings = new ArrayList<>();
strings.add("test");
ProductInfoReq productInfoReq = new ProductInfoReq();
productInfoReq.setPriceType(0);
productInfoReq.setProductIds(strings);
Iap.getIapClient(this).obtainProductInfo(productInfoReq).addOnSuccessListener(new OnSuccessListener<ProductInfoResult>() {
@Override
public void onSuccess(ProductInfoResult result) {
for (ProductInfo productInfo : result.getProductInfoList()) {
System.out.println(productInfo.getProductName());
System.out.println(productInfo.getPrice());
}
}
});
}
//购买
private void purchProduct() {
PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq();
purchaseIntentReq.setProductId("test");
purchaseIntentReq.setPriceType(0);
purchaseIntentReq.setDeveloperPayload("test");
Iap.getIapClient(this).createPurchaseIntent(purchaseIntentReq).addOnSuccessListener(new OnSuccessListener<PurchaseIntentResult>() {
@Override
public void onSuccess(PurchaseIntentResult purchaseIntentResult) {
Status status = purchaseIntentResult.getStatus();
if (status.hasResolution()) {
try {
status.startResolutionForResult(MainActivity2.this,2222);
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
}
});
//推送
private void gettoken() {
new Thread(){
@Override
public void run() {
HmsInstanceId instance = HmsInstanceId.getInstance(MainActivity2.this);
try {
String token = instance.getToken("106402795", "HCM");
System.out.println(token);
} catch (ApiException e) {
System.out.println(e.getMessage());
}
}
}.start();
}
HMS账号登陆
最新推荐文章于 2023-05-18 14:33:53 发布