<uses-permission android:name="android.permission.RECEIVE_SMS" /> <uses-permission android:name="android.permission.WRITE_SMS" /> <uses-permission android:name="android.permission.READ_SMS" />
//BroadcastReceiver public class SmsBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // - , Bundle bundle = intent.getExtras(); // pdus - Object[] pdus = (Object[]) bundle.get("pdus"); if (pdus.length == 0) { return; // } // CMC Sms sms = SmsFromPdus(pdus, context); // , Boolean isClearFromSpam = SuperMegaMethodForResolving Spam(sms, context); if (!isClearFromSpam) { // - CMC abortBroadcast(); return; } } private Sms SmsFromPdus(Object[] pdus, Context context) { Sms sms = new Sms(); for (int i = 0; i < pdus.length; i++) { SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]); sms.Text += smsMessage.getMessageBody(); // (CMC "") } SmsMessage first = SmsMessage.createFromPdu((byte[]) pdus[0]);// sms.SenderId = first.getOriginatingAddress(); // Date receiveDate = new Date(first.getTimestampMillis()); // sms.RecieveDate = receiveDate; sms.Status = first.getStatus(); // (, , ) return sms; } } public class Sms{ public String SenderId; public String Text; public Date RecieveDate; public int Status; }
<receiver android:name="su.Jalapeno.AntiSpam.SystemService.SmsBroadcastReceiver" android:enabled="true" android:exported="true" > <intent-filter android:priority="2147483631" > <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
public class ServiceBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // - } }
<receiver android:name="su.Jalapeno.AntiSpam.SystemService.ServiceBroadcastReceiver" android:exported="true" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
// @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_PICK_ACCOUNT) { if (resultCode == RESULT_OK) { Email = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME); getUsername(); } } super.onActivityResult(requestCode, resultCode, data); } private void pickUserAccount() { String[] accountTypes = new String[] { "com.google" }; Intent intent = AccountPicker.newChooseAccountIntent(null, null, accountTypes, false, null, null, null, null); startActivityForResult(intent, REQUEST_CODE_PICK_ACCOUNT); } // ( Try catch //WEB_CLIENT_ID Client ID for web application final private String WEB_CLIENT_ID = "1999999-aaaaaaaaaaaaaaaaaaaaaaaaa.apps.googleusercontent.com"; //"" Client id. String SCOPE = String.format("audience:server:client_id:%s", WEB_CLIENT_ID); // String token = GoogleAuthUtil.getToken(_activity, Email, SCOPE);
public string GetUserIdByJwt(string jwt, out string userEmail) { userEmail = string.Empty; string userId = null; // Client ID (Client ID for web application) string audience = "111111111111111111-aaaaaaaaaaaaaaaaaaaaa.apps.googleusercontent.com"; // Client ID (Client ID for Android application) string azp = "1111111111111-aaaaaaaaaaaaaaaaaaaaaaaa.apps.googleusercontent.com"; var tokenHandler = new JWTSecurityTokenHandler(); SecurityToken securityToken = tokenHandler.ReadToken(jwt); var jwtSecurityToken = securityToken as JWTSecurityToken; userEmail = GetClaimValue(jwtSecurityToken, "email"); userId = GetClaimValue(jwtSecurityToken, "id"); var validationParameters = new TokenValidationParameters() { AllowedAudience = audience, ValidIssuer = "accounts.google.com", ValidateExpiration = true, // . // Google // Microsoft.IdentityModel ValidateSignature = false, }; try { // Exception, ClaimsPrincipal claimsPrincipal = tokenHandler.ValidateToken(jwtSecurityToken, validationParameters); //, Client Id bool allGood = ValidateClaim(jwtSecurityToken, "azp", azp) && ValidateClaim(jwtSecurityToken, "aud", audience); if (!allGood) { userId = null; } } catch { userId = null; } return userId; } // Claim private static bool ValidateClaim(JWTSecurityToken securityToken, string type, string value) { string claim = GetClaimValue(securityToken, type); if (claim == null) return false; return claim == value; } // Claim ( KeyValuePair) private static string GetClaimValue(JWTSecurityToken securityToken, string type) { var claim = securityToken.Claims.SingleOrDefault(x => x.Type == type); if (claim == null) return null; return claim.Value; }
public class MyApplication extends Application { private static final Products products = Products.create().add(IN_APP, asList(" ", " 2 ")); private final Billing billing = new Billing(this, new Billing.Configuration() { @Nonnull @Override public String getPublicKey() { String base64EncodedPublicKey = " , API "; return base64EncodedPublicKey; } @Nullable @Override public Cache getCache() { return Billing.newCache(); } }); @Nonnull private final Checkout checkout = Checkout.forApplication(billing, products); @Nonnull private static MyApplication instance; public MyApplication() { instance = this; } @Override public void onCreate() { super.onCreate(); billing.connect(); } @Nonnull public static MyApplication get() { return instance; } @Nonnull public Checkout getCheckout() { return checkout; } }
public class BillingActivity extends RoboSherlockActivity { private Sku _skuAccess; @Nonnull protected final ActivityCheckout checkout = Checkout.forActivity(this, MyApplication.get().getCheckout()); @Nonnull protected Inventory inventory; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); _skuAccess = null; _activity = this; checkout.start(); checkout.createPurchaseFlow(new PurchaseListener()); inventory = checkout.loadInventory(); inventory.whenLoaded(new InventoryLoadedListener()); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); checkout.onActivityResult(requestCode, resultCode, data); } @Override protected void onDestroy() { checkout.stop(); checkout.destroyPurchaseFlow(); super.onDestroy(); } @Nonnull public ActivityCheckout getCheckout() { return checkout; } public void Buy(View view) { purchase(_skuAccess); } private void purchase(@Nonnull final Sku sku) { boolean billingSupported = checkout.isBillingSupported(IN_APP); if (!billingSupported) { return; } checkout.whenReady(new Checkout.ListenerAdapter() { @Override public void onReady(@Nonnull BillingRequests requests) { requests.purchase(sku, null, checkout.getPurchaseFlow()); } }); } private class PurchaseListener extends BaseRequestListener<Purchase> { @Override public void onSuccess(@Nonnull Purchase purchase) { onPurchased(); } private void onPurchased() { // - inventory.load().whenLoaded(new InventoryLoadedListener()); } @Override public void onError(int response, @Nonnull Exception ex) { // it is possible that our data is not synchronized with data on // Google Play => need to handle some errors if (response == ResponseCodes.ITEM_ALREADY_OWNED) { onPurchased(); } else { super.onError(response, ex); } } } private class InventoryLoadedListener implements Inventory.Listener { private String _purchaseOrderId; @Override public void onLoaded(@Nonnull Inventory.Products products) { final Inventory.Product product = products.get(IN_APP); if (product.isSupported()) { boolean isPurchased = InspectPurchases(product); // - } } private boolean InspectPurchases(Product product) { List<Sku> skus = product.getSkus(); Sku sku = skus.get(0); // final Purchase purchase = product.getPurchaseInState(sku, Purchase.State.PURCHASED); boolean isPurchased = purchase != null && !TextUtils.isEmpty(purchase.token); if (isPurchased) { // ? return true; } else { // - _skuAccess = sku; return false; } } } private abstract class BaseRequestListener<Req> implements RequestListener<Req> { @Override public void onError(int response, @Nonnull Exception ex) { } } }
Source: https://habr.com/ru/post/240045/
All Articles