How do I open URLs, PDFs, etc. with the default apps?

后端 未结 2 1109
北恋
北恋 2021-02-14 08:56

I am developing an Android application with Delphi XE5, and I would like to know how I can open a URL in the default browser, and a PDF file with the default reader. Developing

相关标签:
2条回答
  • 2021-02-14 09:37

    n00b here can't work out how to add a comment to the set of comments already posted against the previous answer, but I use this, which is another variation on the theme, using constructor parameters:

    procedure LaunchURL(const URL: string);
    var
      Intent: JIntent;
    begin
      Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW,
        TJnet_Uri.JavaClass.parse(StringToJString(URL)));
      SharedActivity.startActivity(Intent);
    end;
    
    0 讨论(0)
  • 2021-02-14 09:50

    For these kind pf task you can use the Intent class which is represented in Delphi by the JIntent interface.

    Try these samples

    Open a URL

    uses
      Androidapi.JNI.GraphicsContentViewText,
      FMX.Helpers.Android;
    
    
    procedure TForm3.Button1Click(Sender: TObject);
    var
      Intent: JIntent;
    begin
      Intent := TJIntent.Create;
      Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
      Intent.setData(StrToJURI('http://www.google.com'));
      SharedActivity.startActivity(Intent);
    end;
    

    Open a PDF File

    uses
      Androidapi.JNI.GraphicsContentViewText,
      Androidapi.JNI.JavaTypes,
      FMX.Helpers.Android;
    
    
    procedure TForm3.Button1Click(Sender: TObject);
    var
      Intent: JIntent;
    begin
      Intent := TJIntent.Create;
      Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
      Intent.setDataAndType(StrToJURI('filepath'),  StringToJString('application/pdf'));
      SharedActivity.startActivity(Intent);
    end;
    
    0 讨论(0)
提交回复
热议问题