Recent

Author Topic: wi-fi connection with android  (Read 7288 times)

Stygian

  • Jr. Member
  • **
  • Posts: 90
wi-fi connection with android
« on: September 16, 2014, 08:43:50 pm »
Hello Guys,

I'm trying to do some network connetion with android. I use Indy which is compile well. I created a simple SMTP with it. but as you know you have to use some .dll under windows if you are try to send mails wot google.

I have two questions:
1, Is this any free smtp where i don't have to use SSL?
2, If no, how I can get .so library for that?

Thanks,
Stygian

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: wi-fi connection with android
« Reply #1 on: September 16, 2014, 08:49:29 pm »
you mean the open ssl library? Isn't that included in all the linux based OS including android?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Stygian

  • Jr. Member
  • **
  • Posts: 90
Re: wi-fi connection with android
« Reply #2 on: September 16, 2014, 08:54:04 pm »
Yes the openssl. I know that linux have that library, but how i tell my program to use them under android?
I don't even know where i should search it.
Is this any treeview of something from the android files?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: wi-fi connection with android
« Reply #3 on: September 16, 2014, 09:12:32 pm »
have you tried to simple build your application that uses it for android and see what happens? If yes what is the error message that your application is generating? I guess that since android is linux based and indy already supports linux it should simple work.

Sorry I have 0 android experience it is in my to learn list though.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Stygian

  • Jr. Member
  • **
  • Posts: 90
Re: wi-fi connection with android
« Reply #4 on: September 16, 2014, 09:15:21 pm »
Only on AVD(It closed itself). But I'll install it. And see what happends

Stygian

  • Jr. Member
  • **
  • Posts: 90
Re: wi-fi connection with android
« Reply #5 on: September 16, 2014, 09:37:47 pm »
Installed it and it's froze when I push the button(Connect).

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: wi-fi connection with android
« Reply #6 on: September 17, 2014, 01:40:54 am »
I'm not better than Taazz. Just a few things:
1- Did you add needed permission sections to your manifest file.
2- Mention more details, like Lazarus/FPC, Android SDK/bin tools, your device, etc.
3- Posting source code encourages people to test, check and help.

Stygian

  • Jr. Member
  • **
  • Posts: 90
Re: wi-fi connection with android
« Reply #7 on: September 17, 2014, 09:06:49 am »
Hello,

I'm not add any files to my project, I need the openssl library I think to start this program properly.
I use LaztoApk version 0.9.026
SDK version 23.0.2
The Lazarus version is 1.3 with FPC 2.7.1
My target device will be a tablet but now i test it on my Dell Steak 5(rooted bootloader open)

I post the source code(btw it's working perfectly on windows):

Code: [Select]
unit Testmain;

{$mode objfpc}{$H+}

{$ifdef Linux}{$ifdef CPUARM}
  {$define Android}
{$endif}{$endif}

interface

uses
  Classes,
  SysUtils,
  FileUtil,
  Forms,
  Controls,
  Graphics,
  Dialogs,
  StdCtrls,
  ExtCtrls,
  StrUtils,
  customdrawnint,
  LCLIntf,
  customdrawncontrols,
  customdrawndrawers,
  customdrawn_common,
  lazdeviceapis,
  IdSMTP,
  IdSSLOpenSSL,
  IdMessage,
  dynlibs;

type

  { TfrmTestMain }

  TfrmTestMain = class(TForm)
    CDButton1: TCDButton;
    CDButton2: TCDButton;
    CDButton3: TCDButton;
    CDinf: TCDStaticText;
    Msg: TIdMessage;
    SSL: TIdSSLIOHandlerSocketOpenSSL;
    SMTP: TIdSMTP;
    procedure CDButton1Click(Sender: TObject);
    procedure CDButton2Click(Sender: TObject);
    procedure CDButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
  public
  end;

var
  frmTestMain: TfrmTestMain;

implementation

{$R *.lfm}

{ TfrmTestMain }

procedure TfrmTestMain.CDButton3Click(Sender: TObject);
begin
  Close;
end;

//this part was for only test but not worked(cause Android is not Windows)
//procedure TfrmTestMain.FormCreate(Sender: TObject);
//var
//  L1Handle, L2Handle: TLibHandle;
//begin
//  L1Handle := LoadLibrary('libeay32.dll');
// L2Handle := LoadLibrary('ssleay32.dll');
//end;
//this part was for only test but not worked(cause Android is not Windows)

procedure TfrmTestMain.CDButton1Click(Sender: TObject);
begin
  SMTP.Username:= 'smtpteszt2014@gmail.com';
  SMTP.Password:= '*********';
  SMTP.Host:= 'smtp.gmail.com';
  SMTP.Port:= 587;
  SSL.Destination:= 'smtp.gmail.com:587';
  if(not SMTP.Connected)then
  begin
    CDinf.Caption:= 'Csatlakozva a(z) smtp.gmail.com kiszolgálóhoz.';
    CDButton1.Caption:= 'Disconnect';
    SMTP.Connect;
    SMTP.Authenticate;
  end else
  begin
    SMTP.Disconnect;
    CDinf.Caption := 'Sikeres lecsatlakozás.';
    CDButton1.Caption := 'Connect';
  end;
end;

procedure TfrmTestMain.CDButton2Click(Sender: TObject);
var
 mydate: string;
begin
  Msg.CharSet:= 'utf-8';
  Msg.From.Name:= UTF8Encode('Sp0T');
  Msg.From.Address:= 'smtpteszt2014@gmail.com';
  Msg.ReplyTo.EMailAddresses:= 'smtpteszt2014@gmail.com';
  Msg.Recipients.EMailAddresses:= mymail@gmail.com';
  mydate := FormatDateTime('yyyy.mm',Now);
  Msg.Subject:= UTF8Encode('Android Test Mail');
  Msg.Body.Text:=UTF8Encode('Hello'+#13#10+#13#10+
                            'I am a test android program.'+#13#10+
                            'Please do not replay to me');
  Msg.Date := Sysutils.Date;
  Msg.MessageParts.Clear;
  SMTP.Send(Msg);
end;

end.

« Last Edit: September 17, 2014, 09:08:49 am by Stygian »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: wi-fi connection with android
« Reply #8 on: September 17, 2014, 05:43:10 pm »
Did you check the logcat output?

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: wi-fi connection with android
« Reply #9 on: September 17, 2014, 05:51:05 pm »
I'd try to find a Java e-mail API and call it via JNI. Here is some java code from a quick search, it should be streight forward to convert it to JNI if it doesn't require interfaces:

http://stackoverflow.com/questions/2020088/sending-email-in-android-using-javamail-api-without-using-the-default-built-in-a

Finding or compiling a SSL native library for Android will probably be headachish ... here is the first result in Google: http://stackoverflow.com/questions/3046573/how-to-use-openssl-library-in-the-android-application

Stygian

  • Jr. Member
  • **
  • Posts: 90
Re: wi-fi connection with android
« Reply #10 on: September 17, 2014, 06:46:02 pm »
I attached the logcat output.

Stygian

  • Jr. Member
  • **
  • Posts: 90
Re: wi-fi connection with android
« Reply #11 on: September 18, 2014, 02:17:42 pm »
@felipemdc: Okay. The base idea is wi-fi communication with another device. I made the SMTP because it's easy to do. But what if I try a simple TFTP server-client communication(no SSL and other crap).

By the way can be the android version missmatch the problem?
I use 4.0.3(API 15) with laztoapk and my phone version is 2.3.3(API 10).
The example program is working prefectly on my phone.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: wi-fi connection with android
« Reply #12 on: September 19, 2014, 09:14:21 am »
I don't know how the FTP implementation is done, so I don't know if it will work in Android. Libraries like Indy were ported to Linux but Android is not identical, so it can work or not work.

The most guaranteed way for it to work is to call a Android Java API via JNI.

Stygian

  • Jr. Member
  • **
  • Posts: 90
Re: wi-fi connection with android
« Reply #13 on: September 19, 2014, 11:38:02 am »
There is an arm-android lib in indy. Maybe I should try "Android Modul Wizard" under linux. Ant can be a good help to create JNI file.

 

TinyPortal © 2005-2018