1

I'm just getting started with java. I'm looking to open chrome to a specific page using a JNI from a button in the UI. I'm getting an error that the chrome file cannot be found. My questions are:

  1. Can be chrome be found in the same place on all android phones?
  2. If so, what is the path?
  3. If not, how would you approach finding the path to chrome here?
  4. Is there an import required on this page to make this function happen?
  5. Do I need to enable a permission in my app package to achieve this?
Runtime runtime = Runtime.getRuntime();    
     String[] s = new String[] {"\\system\\app\\Chrome\\Chrome.apk", "https://www.google.com"}; 
           try
           {
            runtime.exec(s);        
           }
            catch (IOException e)
           {
            e.printStackTrace();
           }

and then the error

W System.err: java.io.IOException: Cannot run program "\system\app\Chrome\Chrome.apk": error=2, No such file or directory

Thank you in advance!

kumarvhat
  • 29
  • 7

1 Answers1

1

You are not using JNI, you are trying to execute an android as it were an executable using the Runtime.exec() method. I don't think that will work in any case. You should try using Android functionality to open Chrome, not methods that would work on other operating systems like Windows or Linux. See this answer for some supported methods: https://stackoverflow.com/a/12013755/721855

aled
  • 21,330
  • 3
  • 27
  • 34
  • Thank you aled. I was able to get things working based off of a block of code in the link you provided. If I could, I would upvote +1 on your answer. I have accepted your answer. Cheers! – kumarvhat May 12 '23 at 14:31