procedure TForm1.ShareFileProvide;
{$IFDEF ANDROID}
var
ExtFile,deger,id:
string;
mime: JMimeTypeMap;
ExtToMime: JString;
Intent: JIntent;
javafile: JFile;
file_name:
String;
{$ENDIF}
begin
{$IFDEF ANDROID}
log.lines.Clear;
file_name := TPath.Combine(TPath.GetHomePath, '
Testfile.txt' );
log.lines.Add('
file_name:'+file_name);
log.lines.Add('
');
TFile.WriteAllText( file_name, Loremipsum, TEncoding.UTF8);
log.lines.Add('
WriteAllText');
log.lines.Add('
');
javafile:=TJFile.JavaClass.init(StringToJString(file_name));
log.lines.Add('
javafile properties:');
log.lines.Add(JStringToString(javafile.getAbsolutePath)) ;
log.lines.Add(JStringToString(javafile.getCanonicalPath)) ;
log.lines.Add(JStringToString(javafile.getPath)) ;
log.lines.Add(JStringToString(javafile.getName)) ;
log.lines.Add('
');
ExtFile := AnsiLowerCase(StringReplace(TPath.GetExtension(file_name), '
.', '
',[]));
log.lines.Add(extfile);
mime := TJMimeTypeMap.JavaClass.getSingleton();
log.lines.Add(JStringToString(mime.toString));
ExtToMime := mime.getMimeTypeFromExtension(StringToJString(ExtFile));
log.lines.Add(JStringToString(ExtToMime));
Intent := TJIntent.Create;
id := JStringToString( TAndroidHelper.Context.getApplicationContext.getPackageName ) + '
.fileprovider';
log.lines.Add('
ID: '+id);
Try
deger := JURIToStr( TJFileProvider.JavaClass.getUriForFile( TAndroidHelper.Context,
StringToJString(id),
javafile)
);
Except
on e:
exception do
Begin
log.lines.Add(e.
message);
exit;
End;
End;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
//Intent.setAction(TJIntent.JavaClass.ACTION_SEND);
Intent.setFlags(1);
Intent.setDataAndType(TAndroidHelperEx.UriFromFile(javafile), ExtToMime);
// Intent.setDataAndType(StrToJURI(deger), ExtToMime);
SharedActivity.startActivity(Intent);
{$ENDIF}
end;