Quantcast
Channel: Planet Object Pascal
Viewing all articles
Browse latest Browse all 1725

while true do;: Sending Android Intents from Delphi (Part 2)

$
0
0

Some months ago I wrote a post with title “Sending Android Intents from Delphi (Part 1)”. In that post I promised to write a 2nd part… here’s it is!

This time I want to play a video deployed with my APK using an external player.

Some informations are available on the Internet, but to correctly know how to play the video I’ve to inspect my Nexus 5 with the LogCat while using the default file manager to start the default video player.

The app main form  is shown below

The main form

The main form

 

I’ve added an mp4 video file using the deployment manager.

This is the code under the button click event

procedure TForm1.Button1Click(Sender: TObject);
var
  Intent: JIntent;
  FileName, DestFileName: string;
  Data: Jnet_Uri;
  CompName: JComponentName;
const
  VIDEO_FILENAME = 'videoviewdemo.mp4';
begin
  FileName := System.IOUtils.TPath.GetDocumentsPath + PathDelim + VIDEO_FILENAME;
  DestFileName := TPath.GetSharedDownloadsPath + PathDelim + VIDEO_FILENAME;
  // Copy the file into a public path (you can use any public path)
  TFile.Copy(FileName, DestFileName, true);
  Data := TJnet_Uri.JavaClass.parse(StringToJString('file://' + DestFileName));
  Intent := TJIntent.Create;
  Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
  if CheckBox1.IsChecked then
  begin
    CompName := TJComponentName.JavaClass.init(StringToJString('android'),
      StringToJString('com.android.internal.app.ResolverActivity'));
    Intent.setComponent(CompName);
  end;
  Intent.setDataAndType(Data, StringToJString('video/mp4'));
  try
    MainActivity.startActivity(Intent);
  except
    on E: Exception do
    begin
      Label1.Text := E.Message;
    end;
  end;
end;

Using the checkbox you can force the OS to show the ResolverActivity.

see you


Viewing all articles
Browse latest Browse all 1725

Trending Articles