Skip to content

Instantly share code, notes, and snippets.

View ponnamkarthik's full-sized avatar

Karthik Ponnam ponnamkarthik

View GitHub Profile
@ponnamkarthik
ponnamkarthik / MainActivity.java
Last active July 28, 2018 23:23
In-app Billing Initalise
BillingClient mBillingClient;
mBillingClient = BillingClient.newBuilder(this).setListener(new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
for(Purchase purchase: purchases) {
//When every a new purchase is made
}
}
}).build();
@ponnamkarthik
ponnamkarthik / MainActivity.java
Last active March 26, 2020 07:06
In-app billing Purchase Item / Subscribe
/**
* To purchase an Product
*/
final List<String> skuList = new ArrayList<>();
skuList.add("product_1"); // SKU Id
SkuDetailsParams params = SkuDetailsParams.newBuilder()
.setSkusList(skuList)
.setType(BillingClient.SkuType.INAPP)
@ponnamkarthik
ponnamkarthik / MainActivity.java
Last active February 11, 2019 04:20
In-app billing Items available for purchase
List<String> skuList = new ArrayList<>();
skuList.add("product_1");
skuList.add("product_2");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
mBillingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
if (responseCode == BillingClient.BillingResponse.OK
@ponnamkarthik
ponnamkarthik / MainActivity.java
Created November 11, 2017 20:19
In-app billing purchased Item List
mBillingClient.queryPurchaseHistoryAsync(SkuType.INAPP,
new PurchaseHistoryResponseListener() {
@Override
public void onPurchaseHistoryResponse(@BillingResponse int responseCode,
List<Purchase> purchasesList) {
if (responseCode == BillingResponse.OK
&& purchasesList != null) {
for (Purchase purchase : purchasesList) {
// Process the result.
}
@ponnamkarthik
ponnamkarthik / MainActivity.java
Created November 11, 2017 20:22
In-app billing consume a purchase
ConsumeResponseListener listener = new ConsumeResponseListener() {
@Override
public void onConsumeResponse(@BillingResponse int responseCode, String outToken) {
if (responseCode == BillingResponse.OK) {
// Handle the success of the consume operation.
// For example, increase the number of coins inside the user's basket.
}
};
mBillingClient.consumeAsync(purchaseToken, listener);
@ponnamkarthik
ponnamkarthik / ActivityMain.java
Created January 13, 2018 10:17
HTTP Utility using retrofit2 and okhttp
private void prepareNetwork() {
File httpCacheDirectory = new File(getCacheDir(), "responses");
int cacheSize = 10 * 1024 * 1024; // 10 MiB
Cache cache = new Cache(httpCacheDirectory, cacheSize);
OkHttpClient client = new OkHttpClient.Builder()
.cache(cache)
.addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
.build();
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'dart:convert';
/*
* TextView with HTML tags support By Kyle Katarn for Dart
*
* Original code by Erik Arvidsson, Mozilla Public License
* http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
* and ported it on JavaScript by John Resig (ejohn.org)
@ponnamkarthik
ponnamkarthik / flutter_native_log.dart
Last active April 22, 2018 09:29
flutter_native_log.dart
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
enum Log {
DEBUG,
WARNING,
ERROR
}
@ponnamkarthik
ponnamkarthik / FlutterNativeLogPlugin.kt
Last active April 22, 2018 09:55
FlutterNativeLogPlugin.kt
package io.github.ponnamkarthik.flutternativelog
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel.Result
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.PluginRegistry.Registrar
import android.util.Log
@ponnamkarthik
ponnamkarthik / FlutterNativeLogPlugin.m
Last active April 22, 2018 10:00
FlutterNativeLogPlugin.m
#import "FlutterNativeLogPlugin.h"
@implementation FlutterNativeLogPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"flutter_native_log"
binaryMessenger:[registrar messenger]];
FlutterNativeLogPlugin* instance = [[FlutterNativeLogPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}