uses
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.Media,
Androidapi.Helpers,
Androidapi.JNI.Net,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.App,
Androidapi.JNI.Os,
Androidapi.JNI.Support,
System.IOUtils;
procedure TTabbedForm.Button1Click(Sender: TObject);
var
Intent: JIntent;
FileName, DestFileName: string;
Data: Jnet_Uri;
CompName: JComponentName;
lFile: JFile;
const
IMAGE_FILENAME = 'small_what.jpg';
begin
FileName := System.IOUtils.TPath.GetPublicPath + PathDelim + IMAGE_FILENAME; // deployed to "assets"
DestFileName := TPath.GetDownloadsPath + PathDelim + IMAGE_FILENAME;
TFile.Copy(FileName, DestFileName, true);
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
if TJBuild_VERSION.JavaClass.SDK_INT >= TJBuild_VERSION_CODES.JavaClass.N then
begin
lFile := TJFile.JavaClass.init(StringToJString(FileName));
Intent.setFlags(TJIntent.JavaClass.FLAG_GRANT_READ_URI_PERMISSION);
Data := TJFileProvider.JavaClass.getUriForFile(TAndroidHelper.Context,
StringToJString('com.embarcadero.TestIntents.fileprovider'), lFile);
end
else
Data := TJnet_Uri.JavaClass.parse(StringToJString('file://' + DestFileName));
Intent.setDataAndType(Data, StringToJString('image/jpg'));
try
TAndroidHelper.Activity.startActivity(Intent);
except
on E: Exception do
begin
Label1.Text := E.Message;
end;
end;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…