Einzelnen Beitrag anzeigen

QuickAndDirty

Registriert seit: 13. Jan 2004
Ort: Hamm(Westf)
1.930 Beiträge
 
Delphi 12 Athens
 
#7

AW: Wie kann ich die Generierung von provider_paths.xml beeinflussen?

  Alt 27. Mär 2019, 16:53
OK wenn ich den URI selber aufbaue geht es auch mit der standard provider_paths.xml
Delphi-Quellcode:
unit Android.FileProviderService;

interface
uses
    System.SysUtils
  , System.ioutils
  , Androidapi.JNI.Os
  , Androidapi.JNI.GraphicsContentViewText
  , Androidapi.JNI.JavaTypes
  , Androidapi.Helpers
  , Androidapi.JNI.Net
  , Androidapi.JNI.Webkit
  ;

type
TFileProviderService = Class
public
  Class procedure SendFileViaFileProvideToChooser(file_name: string);
  Class procedure ViewFileViaFileProvider(file_name: string);
End;

implementation

Class procedure TFileProviderService.SendFileViaFileProvideToChooser(file_name: string);
var
  ExtFile,id, content: string;
  mime: JMimeTypeMap;
  ExtToMime: JString;
  Intent: JIntent;
  javafile: JFile;
  FileURI:JNet_URI;
  ParcelURI:JParcelable;
begin

  javafile:=TJFile.JavaClass.init(StringToJString(file_name));
  ExtFile := AnsiLowerCase(StringReplace(TPath.GetExtension(file_name), '.', '',[]));
  mime := TJMimeTypeMap.JavaClass.getSingleton();
  ExtToMime := mime.getMimeTypeFromExtension(StringToJString(ExtFile));

  Intent := TJIntent.Create;
  id := JStringToString( TAndroidHelper.Context.getApplicationContext.getPackageName ) + '.fileprovider';

  content := 'content://' + id + '/root' + Jstringtostring( javafile.getCanonicalPath );
  FileURI := TJnet_Uri.JavaClass.parse(StringtoJString(content));

  Intent.setAction(TJIntent.JavaClass.ACTION_SEND);
  Intent.SetType(ExtToMime);
  ParcelURI := JParcelable(FileURI);
  Intent.PutExtra(TJIntent.JavaClass.EXTRA_STREAM, ParcelURI);
  SharedActivity.startActivity(TJIntent.JavaClass.createChooser(intent, StrToJCharSequence ('Share With')));
end;


Class procedure TFileProviderService.ViewFileViaFileProvider(file_name: string);
var
  ExtFile,id, content: string;
  mime: JMimeTypeMap;
  ExtToMime: JString;
  Intent: JIntent;
  javafile: JFile;
  FileURI:JNet_URI;
begin
  javafile:=TJFile.JavaClass.init(StringToJString(file_name));
  ExtFile := AnsiLowerCase(StringReplace(TPath.GetExtension(file_name), '.', '',[]));
  mime := TJMimeTypeMap.JavaClass.getSingleton();
  ExtToMime := mime.getMimeTypeFromExtension(StringToJString(ExtFile));

  Intent := TJIntent.Create;
  id := JStringToString( TAndroidHelper.Context.getApplicationContext.getPackageName ) + '.fileprovider';

  content := 'content://' + id + '/root' + Jstringtostring( javafile.getCanonicalPath );
  FileURI := TJnet_Uri.JavaClass.parse(StringtoJString(content));

  Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
  Intent.setFlags(1);
  Intent.setDataAndType(FileURI, ExtToMime); // Intent.setDataAndType(StrToJURI(deger), ExtToMime);
  SharedActivity.startActivity(Intent);
end;
Andreas
Monads? Wtf are Monads?

Geändert von QuickAndDirty (27. Mär 2019 um 16:58 Uhr)
  Mit Zitat antworten Zitat