procedure TicTrainerF.HandleActivityMessageGPXRead(
const Sender: TObject;
const M: TMessage);
var
//P: TJavaObjectArray<Jstring>;
Data:JIntent;
C: JCursor;
I: integer;
uri,filename:
String;
ms: TMemoryStream;
jis: JInputStream;
b: TJavaArray<Byte>;
begin
if (M
is TMessageResultNotification)
then
begin
mlog.info('
start to read GPX-file');
TMessageManager.DefaultManager.Unsubscribe(TMessageResultNotification, HandleActivityMessageGPXRead);
data:=TMessageReceivedNotification(M).Value;
if (data=nil)
then
begin
mlog.info('
nothing to Import');
exit;
end;
uri:=JStringToString(Data.getData.toString);
//P:=TJavaObjectArray<Jstring>.create(1);
//P.Items[0]:=StringToJstring('_data');
mlog.info('
try to get GPX-File from: '+
uri);
C := MainActivity.getContentResolver.query(Data.getData,
nil {P}, StringToJString('
'),
nil, StringToJString('
'));
C.moveToFirst;
for I := 0
to C.getColumnCount - 1
do
begin
if JStringToString(C.getColumnName(I)) = '
_display_name'
then
begin
filename:=JStringToString(C.getString(I));
Break;
end;
end;
mlog.info('
try to store GPX-File: '+filename);
if ((
not lowercase(filename).endsWith('
.gpx'))
and (
not lowercase(filename).endsWith('
.zip')))
then
begin
showInfo(translation.get(3066,'
The file')+'
|'+filename+'
|'+translation.get(3067,'
is not a GPX-File.'),TMsgDlgType.mtError);
exit;
end;
ms := TMemoryStream.Create();
try
jis := TAndroidHelper.Context.getContentResolver.openInputStream(Data.getData);
b := TJavaArray<Byte>.Create(jis.available);
jis.
read(b);
ms.
Write(b.Data^, b.Length);
jis.close;
mlog.info('
prepare save GPX-file to '+filename+'
'+IntToStr(b.length));
TFileUtils.checkDirSequence(TFileUtils.adjustDir(eConfigMyExerciseDirectory.text)+'
GPX');
filename:=TFileUtils.adjustDir(TFileUtils.adjustDir(eConfigMyExerciseDirectory.text)+'
GPX')+filename;
//filename:=StringReplace(filename,' ','',[rfReplaceAll]); //bad to search for the video
mlog.info('
save GPX-file to '+filename+'
'+IntToStr(b.length));
ms.saveToFile(filename);
mlog.info('
saved GPX-file');
finally
ms.free();
end;
mlog.info('
read GPX-file '+filename);
readExerciseFromGPX(btWizardGPXRead,filename,true,true);
end;
end;