Einzelnen Beitrag anzeigen

QuickAndDirty

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

AW: Share file via Provider

  Alt 27. Mär 2019, 12:20
Ich bekomme folgendes log und Exception aus dem code
Code:
file_name:/data/user/0/com.embarcadero.ShareFiletest/files/Testfile.txt

WriteAllText

javafile properties:
/data/user/0/com.embarcadero.ShareFiletest/files/Testfile.txt
/data/data/com.embarcadero.ShareFiletest/files/Testfile.txt
/data/user/0/com.embarcadero.ShareFiletest/files/Testfile.txt
Testfile.txt

txt
android.webkit.MimeTypeMap@74138ac
text/plain
ID: com.embarcadero.ShareFiletest.fileprovider
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.embarcadero.ShareFiletest/files/Testfile.txt
Delphi-Quellcode:
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;
Wie kommt er darauf die Datei nicht finden zu können?
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/data/com.embarcadero.ShareFiletest/files/Testfile.txt
Andreas
Monads? Wtf are Monads?
  Mit Zitat antworten Zitat