I have a method inside the cpp shared library which uses system() call to execute an android command. I have a cpp executable as well which uses this shared library and calls that particular method. When the executable calls the method inside shared library, the method successfully calls system() and I can see the android command ran successfully. Now, I have a xamarin app which also loads the same shared cpp library and calls the same method from the shared library. However, this time, the system() call fails and it can't execute the Android command. The Android command is to open browser
Why is it not working when called from Xamarin app? Do I need to provide any specific permissions to the app. I know that the app has permissions to access storage and internet.
std::string getName()
{
std::streambuf* cout_sbuf = std::cout.rdbuf(); // save original
std::ofstream fout("/sdcard/cout.txt");
std::cout.rdbuf(fout.rdbuf()); // redirect 'cout' to a 'fout'
std::string httpUrl = "https://www.google.com";
std::string cmd = "/system/bin/am start -a
android.intent.action.VIEW -d \"" + httpUrl + "\"";
std::cout<<"cmd passing to system(): "<< cmd <<std::endl;
if(system(cmd.c_str())==0)
{
std::cout<<"system() returned successful. Return value: " <<
system(cmd.c_str()) <<std::endl;
}
else
{
std::cout<<"system() returned failure. Return value: " <<
system(cmd.c_str()) <<std::endl;
}
std::cout.rdbuf(cout_sbuf); // restore the original stream buffer
return "return from getName()";
}
The above code works fine when we run a cpp exe from the command line. However, it won't work when the xamarin app calls this method. The return code of system() is 65280