Last active
July 9, 2021 11:57
-
-
Save RageshAntony/93f77677cb69720616254fc710dd7832 to your computer and use it in GitHub Desktop.
MethodChannal ccAvenuePayment not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity: FlutterActivity() { | |
private val CHANNEL = "Method_Channel" | |
lateinit var inInit: OnHeadlineSelectedListener | |
val result = MutableLiveData<String> ().apply { value = "" } | |
interface OnHeadlineSelectedListener { | |
fun onArticleSelected(position: Int) | |
} | |
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { | |
val streamHandlerImpl = UpdateStackMemoryStream() | |
inInit=streamHandlerImpl | |
streamHandlerImpl.startListening(flutterEngine.dartExecutor) | |
GeneratedPluginRegistrant.registerWith(flutterEngine) | |
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { | |
// Note: this method is invoked on the main thread. | |
call, result -> | |
if (call.method == "ccAvenuePayment") { | |
Log.d("CALL","method : "+call.method) // NOT CALLED !!! | |
val json = JSONObject(call.argument<String>("params")) | |
val intent = Intent(this, mumbai.dev.testapp.MainActivity::class.java) | |
intent.putExtra("currency",json.optString("currency")) | |
intent.putExtra("amount",json.optDouble("amount")) | |
intent.putExtra("custId",json.optString("custId")) | |
intent.putExtra("param1",json.optString("param1")) | |
startActivityForResult(intent,123) | |
} else { | |
result.notImplemented() | |
} | |
} | |
val event = EventChannel(flutterEngine?.dartExecutor?.binaryMessenger,"trans") | |
event.setStreamHandler(object : EventChannel.StreamHandler { | |
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) { | |
this@MainActivity.result.observe(this@MainActivity, Observer { | |
if (it?.isNotBlank() == true) { | |
events?.success(it) | |
Toast.makeText(this@MainActivity, "Call fluttwe", Toast.LENGTH_SHORT).show() | |
result.postValue("") | |
} | |
}) | |
} | |
override fun onCancel(arguments: Any?) { | |
} | |
}) | |
} | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
if (resultCode == Activity.RESULT_OK && requestCode == 123) { | |
val json = JSONObject(data?.getStringExtra("trans")?.trim()) | |
result.postValue(json.toString(1)) | |
} | |
} | |
// Checks if external storage is available for read and write | |
fun isExternalStorageWritable(): Boolean { | |
val state = Environment.getExternalStorageState() | |
return if (Environment.MEDIA_MOUNTED == state) { | |
true | |
} else false | |
} | |
//Checks if external storage is available to at least read | |
fun isExternalStorageReadable(): Boolean { | |
val state = Environment.getExternalStorageState() | |
return if (Environment.MEDIA_MOUNTED == state || Environment.MEDIA_MOUNTED_READ_ONLY == state) { | |
true | |
} else false | |
} | |
override fun onTrimMemory(level: Int) { | |
if (level >= ComponentCallbacks2.TRIM_MEMORY_COMPLETE && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) { | |
this.cacheDir.deleteRecursively() | |
inInit.onArticleSelected(level) | |
} | |
super.onTrimMemory(level) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void callCCAvenuePayment() async { | |
print ("calling Android"); | |
try { | |
var payment = PaymentParams( | |
currency: globals.preferredCurrency, | |
amount: double.parse(_viewModel.walletAmount.text.trim()), | |
custId: globals.userid, | |
param1: globals.phnNo ?? ""); | |
var accountToken=await platform.invokeMethod("ccAvenuePayment", {"params": jsonEncode(payment.toJson())}); | |
print("print result from CCAvenue: "+accountToken); | |
} on PlatformException catch (e) { | |
print("CCAvenue Call error"+e.message); | |
} | |
} | |
EventChannel _stream = EventChannel('trans'); | |
_stream.receiveBroadcastStream().listen( | |
(data) { | |
setState(() { | |
//_batteryLevel = batteryLevel; | |
// respController.text = data.toString(); | |
Toast().show(context: context, message: "Payed"); | |
}); | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment