Wednesday, 18 May 2022

Flutter: Intent

I try to call an Intent request from my Flutter/Android project. As described, it should be done as follows

Intent intent = ​new ​Intent();
intent.setComponent(​new ​ComponentName(​"sk.co.xxx.yyy"​, "sk.co.xxx.yyy.MainActivity"​));
JSONObject jReq = ​new ​JSONObject();
String sReq=​""​;
jReq.put(​"Amount"​,​<Amount>​); 
jReq.put(​"Operation"​,​<Operation>​);
jReq.put(​"TransactionID"​,<can be generated e.g.getRandom()>); 
sReq = jReq.toString();

if​(sReq.isEmpty())​return​; 
intent.putExtra(​"POS_EMULATOR_EXTRA"​, sReq); try ​{
startActivityForResult(intent, ​<requestCode>​); }

How to implement this code under Flutter? I tried to use android_intent package from flutter.dev but i I get the following error message:

E/MethodChannel#plugins.flutter.io/android_intent(22815): Failed to handle method call
E/MethodChannel#plugins.flutter.io/android_intent(22815): android.content.ActivityNotFoundException: No Activity found to handle Intent 

Thanks for any answers!

my Flutter code, to replace the code above, is:

if (Platform.isAndroid) {
    Map data = {
      "Amount": "$amount",
      "Operation": "$operation"
    };
  AndroidIntent intent = AndroidIntent(
    componentName: "sk.co.xxx.yyy"​,
    data: data.toString()
  );
  await intent.launch();

I see, that "MainActivity" and putExtra(​"POS_EMULATOR_EXTRA" are not in my Flutter code, but i don't now, how i can implement...



from Flutter: Intent

No comments:

Post a Comment