LAMW jShareFile lazarus / 43-Android ---------------------------------------------------------------------- Odanka · 2018-12-27 01:48 In the previous problem about how to share file on android 6+, Solved by RunTimePermission. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i jShareFiles.ShareFrom(GetEnvironmentDirectoryPath(dirDCIM) + '/Mayari/estimasi.jpg', 'image/*'); This code work properly but only once and if I try to execute again will fail. I close the apps and run again and code work again. Anyone Please.. Thank you. ---------------------------------------------------------------------- jmpessoa · 2018-12-27 03:46 Hi, Odanka! Please, put/attachment  you  entire/complete unit code.... ---------------------------------------------------------------------- Odanka · 2018-12-27 04:39 Here is the entire code of child form Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {Hint: save all files to location: D:\it\mobile\Mayari\jni }unit perpanjangan; {$mode delphi} interface uses  Classes, SysUtils, AndroidWidget, Laz_And_Controls, sviewpager, stextinput, stablayout,  sfloatingbutton, scoordinatorlayout, drawingview, sharefile, intentmanager,  And_jni; type   { TAndroidModule_Perpanjangan }   TAndroidModule_Perpanjangan = class(jForm)    jCanvass: jCanvas;    jDrawingViews: jDrawingView;    jIntentManagers: jIntentManager;    jListViews: jListView;    jPanel_Input: jPanel;    jPanels: jPanel;  jsCoordinatorLayouts: jsCoordinatorLayout;    jScrollViews: jScrollView;    jsFloatingButtons: jsFloatingButton;    jShareFiles: jShareFile;    jsTabLayouts: jsTabLayout;    jsTextInput_SWDKLLJ_Pokok: jsTextInput;    jsTextInput_PKB: jsTextInput;    jsTextInput_JTPKB: jsTextInput;    jsTextInput_SWDKLLJ_Denda: jsTextInput;    jsTextInput_AdmSTNKB: jsTextInput;    jsTextInput_Jasa: jsTextInput;    jsTextInput_Tanggal: jsTextInput;    jsTextInput_NoPol: jsTextInput;    jsViewPagers: jsViewPager;    procedure AndroidModule_PerpanjanganCreate(Sender: TObject);    procedure AndroidModule_PerpanjanganJNIPrompt(Sender: TObject);    procedure jDrawingViewsDraw(Sender: TObject; countXY: integer;      X: array of single; Y: array of single; flingGesture: TFlingGesture;      pinchZoomScaleState: TPinchZoomScaleState; zoomScale: single);    procedure jsFloatingButtonsClick(Sender: TObject);    procedure jsTabLayoutsTabSelected(Sender: TObject; position: integer; title: string);  private    {private declarations}    procedure SetInputData;    procedure GetEstimasi;  public    {public declarations}  end; var  AndroidModule_Perpanjangan: TAndroidModule_Perpanjangan; implementation uses main, Common; {$R *.lfm}  { TAndroidModule_Perpanjangan } procedure TAndroidModule_Perpanjangan.AndroidModule_PerpanjanganJNIPrompt(  Sender: TObject);begin   // Initilization  jsViewPagers.AddPage(jPanel_Input.View, 'Data');  jsViewPagers.AddPage(jListViews.View, 'Estimasi');   jsTabLayouts.BackgroundColor := colbrGoldenRod;  jsTabLayouts.SetTabTextColors(colbrWhiteSmoke, colbrYellow);  jsTabLayouts.SetSelectedTabIndicatorColor(colbrYellow);  jsTabLayouts.SetupWithViewPager(jsViewPagers.View);   // Data Initilization  jsTextInput_Tanggal.Text := FormatDateTime('dd/mm/yyyy', now, FormatSettings);  jsTextInput_NoPol.Text := '';  jsTextInput_PKB.Text := '';  jsTextInput_JTPKB.Text := jsTextInput_Tanggal.Text;  jsTextInput_SWDKLLJ_Pokok.Text := '';  jsTextInput_SWDKLLJ_Denda.Text := '';  jsTextInput_AdmSTNKB.Text := '';  jsTextInput_Jasa.Text := '';   // Set Input Data  SetInputData;end; procedure TAndroidModule_Perpanjangan.AndroidModule_PerpanjanganCreate(Sender: TObject);begin  jDrawingViews.Height := 1000;  jDrawingViews.Width := 480;  jDrawingViews.LayoutParamHeight := lpExact;  jDrawingViews.LayoutParamWidth := lpExact;end; procedure TAndroidModule_Perpanjangan.jDrawingViewsDraw(Sender: TObject;  countXY: integer; X: array of single; Y: array of single;  flingGesture: TFlingGesture; pinchZoomScaleState: TPinchZoomScaleState;  zoomScale: single);var  w, h: integer;begin  w := jDrawingViews.Width;  h := jDrawingViews.Height;  jDrawingViews.PaintColor := colbrBlack;   // Frame  jDrawingViews.DrawLine(20, 20, w - 20, 20);  jDrawingViews.DrawLine(20, h - 20, w - 20, h - 20);  jDrawingViews.DrawLine(20, 20, 20, h - 20);  jDrawingViews.DrawLine(w - 20, 20, w - 20, h - 20);   // Header ------------------------------- -----------------------------------------------  jDrawingViews.DrawTextAligned('BIRO JASA MAYARI', 40, 40, w - 40,    40, thCenter, tvBottom);  jDrawingViews.DrawTextAligned('Estimasi Perpanjangan Tahunan', 40, 65, w - 40,    65, thCenter, tvBottom);  jDrawingViews.DrawLine(20, 75, w - 20, 75);   // Data Perpanjangan -------------------------------------------------------------------  { Tanggal }  jDrawingViews.DrawTextAligned('Tanggal', 40, 100, w - 40, 100, thLeft, tvBottom);  jDrawingViews.DrawTextAligned(':', 40, 100, w - 40, 100, thCenter, tvBottom);  jDrawingViews.DrawTextAligned(FormatDateTime('dd/mm/yyyy', _Tanggal,  FormatSettings), 40, 100, w - 40, 100, thRight, tvBottom);   { No. Polisi }  jDrawingViews.DrawTextAligned('No. Polisi', 40, 125, w - 40, 125, thLeft, tvBottom);  jDrawingViews.DrawTextAligned(':', 40, 125, w - 40, 125, thCenter, tvBottom);  jDrawingViews.DrawTextAligned(jsTextInput_NoPol.Text, 40, 125, w -    40, 125, thRight, tvBottom);   { Pajak Pokok }  jDrawingViews.DrawTextAligned('Pajak', 40, 150, w - 40, 150, thLeft, tvBottom);  jDrawingViews.DrawTextAligned(':', 40, 150, w - 40, 150, thCenter, tvBottom);  jDrawingViews.DrawTextAligned(Format('%0.0n', [_PKB]), 40, 150, w -    40, 150, thRight, tvBottom);   { Jatuh Tempo Pajak }  jDrawingViews.DrawTextAligned('J/TPajak', 40, 175, w - 40, 175, thLeft, tvBottom);  jDrawingViews.DrawTextAligned(':', 40, 175, w - 40, 175, thCenter, tvBottom);  jDrawingViews.DrawTextAligned(FormatDateTime('dd/mm/yyyy', _JTPKB, FormatSettings),    40, 175, w - 40, 175, thRight, tvBottom);   // Estimasi Biaya ------------------------------------------------------- ---------------  jDrawingViews.DrawTextAligned('ESTIMASI BIAYA', 40, 225, w - 40,    225, thCenter, tvBottom);   { Pajak dan Denda }  jDrawingViews.DrawTextAligned('Pajak dan Denda (PKB)', 40, 250, w -  40, 250, thLeft, tvBottom);  jDrawingViews.DrawTextAligned(':', 40, 250, w - 40, 250, thCenter, tvBottom);  jDrawingViews.DrawTextAligned(Format('%0.0n', [RekalkulkasiPajakDenda]),    40, 250, w - 40, 250, thRight, tvBottom);   { SWDKLLJ dan Denda }  jDrawingViews.DrawTextAligned('SWDKLLJ dan Denda', 40, 275, w - 40,  275, thLeft, tvBottom);  jDrawingViews.DrawTextAligned(':', 40, 275, w - 40, 275, thCenter, tvBottom);  jDrawingViews.DrawTextAligned(Format('%0.0n', [RekalkulasiSWDKLLJDenda]),    40, 275, w - 40, 275, thRight, tvBottom);   { Administrasi STNK/TNKB }  jDrawingViews.DrawTextAligned('Adm. STNK/TNKB', 40, 300, w - 40,    300, thLeft, tvBottom);  jDrawingViews.DrawTextAligned(':', 40, 300, w - 40, 300, thCenter, tvBottom);  jDrawingViews.DrawTextAligned(Format('%0.0n', [_AdmSTNKB]),    40, 300, w - 40, 300, thRight, tvBottom);   { Jasa }  jDrawingViews.DrawTextAligned('Jasa', 40, 325, w - 40,    325, thLeft, tvBottom);  jDrawingViews.DrawTextAligned(':', 40, 325, w - 40, 325, thCenter, tvBottom);  jDrawingViews.DrawTextAligned(Format('%0.0n', [_Jasa]),    40, 325, w - 40, 325, thRight, tvBottom);   { Jumlah }  jDrawingViews.DrawLine(40, 350, w - 40, 350);  jDrawingViews.DrawTextAligned('JUMLAH', 40, 375, w - 40,    375, thLeft, tvBottom);  jDrawingViews.DrawTextAligned(':', 40, 375, w - 40, 375, thCenter, tvBottom);  jDrawingViews.DrawTextAligned(Format('%0.0n', [RekalkulasiJumlahPerpanjangan]),    40, 375, w - 40, 375, thRight, tvBottom);   { Denda }  jDrawingViews.DrawTextAligned(Format('*Denda : %0.0d (Hari)', [GetDendaHari]),    40, h - 105, w - 40, h - 105, thLeft, tvBottom);   // Footer --------------------------------------- ---------------------------------------  jDrawingViews.DrawLine(20, h - 80, w - 20, h - 80);  jDrawingViews.DrawTextAligned('Biaya pajak, denda dan BBN disesuaikan dengan',    40, h - 55, w - 40, h - 55, thCenter, tvBottom);  jDrawingViews.DrawTextAligned('notice pajak/STNK asli',    40, h - 30, w - 40, h - 30, thCenter, tvBottom);end; procedure TAndroidModule_Perpanjangan.jsFloatingButtonsClick(Sender: TObject);var  permissionGranted: boolean;begin   case jsTabLayouts.GetPosition() of    0:    begin      AndroidModule_Main.jsToolbar_Main.SetSubtitle('');      jsCoordinatorLayouts.RemoveFromViewParent();      FreeAndNil(AndroidModule_Perpanjangan);    end;    1:    begin      permissionGranted := IsRuntimePermissionGranted(        'android.permission.WRITE_EXTERNAL_STORAGE');      if permissionGranted then      begin        if not (DirectoryExists(GetEnvironmentDirectoryPath(dirDCIM) + '/Mayari')) then          CreateDir(GetEnvironmentDirectoryPath(dirDCIM), 'Mayari');        jDrawingViews.Refresh;        jDrawingViews.SaveToFile(GetEnvironmentDirectoryPath(dirDCIM) + '/Mayari',          'estimasi.jpg');         jShareFiles.ShareFrom(GetEnvironmentDirectoryPath(dirDCIM) +          '/Mayari/estimasi.jpg', 'image/*');         {        jIntentManagers.SetAction(jIntentManagers.GetActionSendAsString());      jIntentManagers.SetMimeType('image/*');        jIntentManagers.PutExtraFile(GetEnvironmentDirectoryPath(dirDCIM),        'estimasi.jpg');        if jIntentManagers.ResolveActivity() then           jIntentManagers.StartActivity();        }      end    else      begin        ShowMessage('Permission needed..!');      end;    end;  end;end; procedure TAndroidModule_Perpanjangan.jsTabLayoutsTabSelected(Sender: TObject;  position: integer; title: string);begin  case position of    0: jsFloatingButtons.ImageIdentifier := 'ic_home_white';    1:    begin    jsFloatingButtons.ImageIdentifier := 'ic_share_white';      GetEstimasi;    end;  end;end; procedure TAndroidModule_Perpanjangan.SetInputData;begin  if not (TryStrToDate(jsTextInput_Tanggal.Text, _Tanggal)) then    _Tanggal := now;   _NoPolisi := jsTextInput_NoPol.Text;   if not (TryStrToFloat(jsTextInput_PKB.Text, _PKB)) then    _PKB := 0;   if not (TryStrToDate(jsTextInput_JTPKB.Text, _JTPKB)) then    _JTPKB := now;   if not (TryStrToFloat(jsTextInput_SWDKLLJ_Pokok.Text, _SWDKLLJ_Pokok)) then    _SWDKLLJ_Pokok := 0;   if not (TryStrToFloat(jsTextInput_SWDKLLJ_Denda.Text, _SWDKLLJ_Denda)) then  _SWDKLLJ_Denda := 0;   if not (TryStrToFloat(jsTextInput_AdmSTNKB.Text, _AdmSTNKB)) then    _AdmSTNKB := 0;   if not (TryStrToFloat(jsTextInput_Jasa.Text, _Jasa)) then    _Jasa := 0;end; procedure TAndroidModule_Perpanjangan.GetEstimasi;begin  SetInputData;  jListViews.Clear;   // Data  jListViews.Add('PERPANJANGAN TAHUNAN');  jListViews.Add(Format('    Tanggal(|)%s',    [FormatDateTime('dd/mm/yyyy', _Tanggal, FormatSettings)]));  jListViews.Add(Format('    No. Polisi(|)%s', [jsTextInput_NoPol.Text]));  jListViews.Add(Format('    Pajak(|)%0.0n', [_PKB]));  jListViews.Add(Format('    J/T Pajak(|)%s',    [FormatDateTime('dd/mm/yyyy', _JTPKB, FormatSettings)]));  jListViews.Add(Format('    SWDKLLJ Pokok(|)%0.0n', [_SWDKLLJ_Pokok]));  jListViews.Add(Format('    SWDKLLJ Denda(|)%0.0n', [_SWDKLLJ_Denda]));   // Estimasi  jListViews.Add('ESTIMASI BIAYA');  jListViews.Add(Format('    Denda(|)%0.0d Hari', [GetDendaHari]));  jListViews.Add(Format('    Pajak dan Denda(|)%0.0n', [RekalkulkasiPajakDenda]));  jListViews.Add(Format('    SWDKLLJ dan Denda(|)%0.0n', [RekalkulasiSWDKLLJDenda]));  jListViews.Add(Format('    Adm STNK/TNKB(|)%0.0n', [_AdmSTNKB]));  jListViews.Add(Format('    Jasa(|)%0.0n', [_Jasa]));  jListViews.Add(Format('    JUMLAH(|)%0.0n', [RekalkulasiJumlahPerpanjangan])); end; end.  Runtime Perrmission in Main Form Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {Hint: save all files to location: D:\it\mobile\Mayari\jni }unit main; {$mode delphi} interface uses  Classes, SysUtils, AndroidWidget, sdrawerlayout, snavigationview, Laz_And_Controls,  stoolbar, imagefilemanager; type   { TAndroidModule_Main }   TAndroidModule_Main = class(jForm)    jImageFileManagers: jImageFileManager;    jImageViews: jImageView;    jPanel_Apps: jPanel;    jPanel_Logo: jPanel;    jPanel_Main: jPanel;    jsDrawerLayout_Main: jsDrawerLayout;    jsNavigationView_Main: jsNavigationView;    jsToolbar_Main: jsToolbar;    procedure AndroidModule_MainJNIPrompt(Sender: TObject);    procedure jsNavigationView_MainClickItem(Sender: TObject;      itemId: integer; itemCaption: string);    procedure jsToolbar_MainClickNavigationIcon(Sender: TObject);  private    {private declarations}  public    {public declarations}  end; var  AndroidModule_Main: TAndroidModule_Main; implementation uses perpanjangan, perpanjangan5t; {$R *.lfm}  { TAndroidModule_Main } procedure TAndroidModule_Main.AndroidModule_MainJNIPrompt(Sender: TObject);var  mnuObject: jObjectRef;  manifestPermissions: TDynArrayOfString;begin  // Runtime Permission  if IsRuntimePermissionNeed() then  begin    SetLength(manifestPermissions, 1);    manifestPermissions[0] := 'android.permission.WRITE_EXTERNAL_STORAGE';    RequestRuntimePermission(manifestPermissions, 1001);    SetLength(manifestPermissions, 0);  end;   // Toolbar  jsToolbar_Main.SetBackgroundToPrimaryColor();  jsToolbar_Main.SetTitleTextColor(colbrWhite);  jsToolbar_Main.SetTitle('BIRO JASA MAYARI');  jsToolbar_Main.SetSubtitleTextColor(colbrWhite);   // Navigation Drawer  jsNavigationView_Main.AddHeaderView(colbrGoldenRod, 'ic_launcher', 'BIRO JASA MAYARI',    180);  mnuObject := jsNavigationView_Main.GetMenu();  jsNavigationView_Main.AddItem(mnuObject, 100, 'Perpanjangan Tahunan');  jsNavigationView_Main.AddItem(mnuObject, 101, 'Perpanjangan 5 Tahunan');  jsNavigationView_Main.AddItem(mnuObject, 102, 'Kehilangan STNK');  jsNavigationView_Main.AddItem(mnuObject, 103, 'Mutasi');  jsNavigationView_Main.AddItem(mnuObject, 104, 'BBN');  jsNavigationView_Main.AddItem(mnuObject, 105, 'Seting');   // Under Construction  jImageViews.SetImage(jImageFileManagers.LoadFromAs sets('Mayari.png'));  jPanel_Logo.BringToFront();end; procedure TAndroidModule_Main.jsNavigationView_MainClickItem(Sender: TObject;  itemId: integer; itemCaption: string);begin  jImageViews.SetImage(jIma geFileManagers.LoadFromAssets('Mayari.png'));  jsDrawerLayout_Main.CloseDrawers();  jsToolbar_Main.SetSubtitle('');  jPanel_Apps.RemoveAllViews();   if AndroidModule_Perpanjangan <> nil then    FreeAndNil(AndroidModule_Perpanjangan);  if AndroidModule_Perpanjangan5t <> nil then    FreeAndNil(AndroidModule_Perpanjangan5t);   case itemId of    // Perpanjangan Tahunan    100:    begin      jsToolbar_Main.SetSubtitle('Perpanjangan Tahunan');      if AndroidModule_Perpanjangan = nil then        gApp.CreateForm(TAndroidModule_Perpanjangan, AndroidModule_Perpanjangan);      AndroidModule_Perpanjangan.Init(gApp);      AndroidModule_Perpanjangan .jsCoordinatorLayouts.SetViewParent(jPanel_Apps.View);      jPanel_Apps.BringToFront();    end;    // Perpanjangan 5 tahunan    101:    begin      jsToolbar_Main.SetSubtitle('Perpanjangan 5 Tahunan');      if AndroidModule_Perpanjangan5t = nil then        gApp.CreateForm(TAndroidModule_Perpanjangan5t, AndroidModule_Perpanjangan5t);      AndroidModule_Perpanjangan5t.Init(gApp);      AndroidModule_Perpanjang an5t.jsCoordinatorLayouts.SetViewParent(jPanel_Apps.View);      jPanel_Apps.BringToFront();    end;    else    begin      jImageViews. SetImage(jImageFileManagers.LoadFromAssets('UnderConstruction.png'));      jPanel_Logo.BringToFront();    end;  end;end; procedure TAndroidModule_Main.jsToolbar_MainClickNavigationIcon(Sender: TObject);begin  jsDrawerLayout_Main.OpenDrawer();end; end. Is it the problem when Request Permission in different form? Thank you. ---------------------------------------------------------------------- jmpessoa · 2018-12-27 05:35 QuoteIs it the problem when Request Permission in different form? No!!! But, move this code from "OnCreate": Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  jDrawingViews.Height := 1000;  jDrawingViews.Width := 480;  jDrawingViews.LayoutParamHeight := lpExact;  jDrawingViews.LayoutParamWidth := lpExact; to "OnJNIPrompt"   ....    [OnCreate handle only pascal side code...] ---------------------------------------------------------------------- Odanka · 2018-12-27 06:56 Hi, jmpessoa Thank you but the same problem still occur and attachments is the complete project but only jni and assets folder due to the restrictions of file size. Note: Project compiled by Target: Android CPU:i386 and run on virtual device of Android 7.1.1 API 25. ---------------------------------------------------------------------- Odanka · 2019-01-02 00:43 I try make a little modification of Java Source Code: Code: Javascript  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i         public void ShareFrom(String _fullFilename, String _mimetype) {                 int p1 = _fullFilename.lastIndexOf("/");                   String filename = _fullFilename.substring(p1+1, _fullFilename.length());                                                 File file = new File(_fullFilename);                                   intent.setType(_mimetype);                   // A little modification Use Uri.parse instead of Uri.fromFile                   intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(_fullFilename));                  controls.activity.startActivity(Intent.createChooser(intent, "Share ["+filename+"] by:"));                      }         This code work properly to share the image via WhatApps on Real Device but not work when share by the other apps like messanger, SMS (MMS), etc.