📜 ⬆️ ⬇️

Connecting ATOL KKM to AndroidStudio (update to FZ-54)

Good afternoon, Habr. Last summer, I had to connect ATOL KKM to the project in AndroidStudio. Having successfully coped with the task, I published a post on Habré to ease the way for those who go my way: Connect the ATOL CMC to AndroidStudio .

In light of the legislation update (FZ-54), updated drivers were released for the ATOL KKM, which require a slightly different approach for connection than the one described earlier.


')
Under the cut, you will see exactly what I did. But I’ll say right away that the Android development pro will probably not find anything interesting for themselves, but for beginners like me, it will ease the development path a little.

To connect the updated drivers, the following steps were taken:

1) Delete the old module from the project: File - Project Structure - select the old module from the Modules section, and click on the red minus;
2) Added a new module: File - New - Import Module - look for the folder (in the provided folder, I have: Trade_equipment_drivers / android / jar) FptrLibRes and add it to the project;
3) Further, as in the previous article, add to jniLibs (path: app / src / main), folders armeabi and armeabi-v7a;
4) Add to the libs folder (path: app / src / main) - jar files: fptrlib.jar, fptrproxylib.jar, paycardlib.jar, usblib.jar Right-click on the jar-files, and select "Add As Library ";
5) We make changes to gradle (I give an example from a test project that was created for the last article):

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' compile project(':fptrRes') compile files('src/main/libs/fptrproxylib.jar') compile files('src/main/libs/paycardlib.jar') compile files('src/main/libs/usblib.jar') compile files('src/main/libs/fptrlib.jar') } 

6) From the manifest, delete the lines (if they were, as in the last test project):

  <activity android:name="com.atol.drivers.fptr.settings.SettingsActivity" android:label=" " android:windowSoftInputMode="adjustPan"> <intent-filter> <action android:name="android.intent.action.VIEW"/> </intent-filter> </activity> <activity android:name="com.atol.drivers.fptr.settings.DeviceListActivity" android:configChanges="orientation|keyboardHidden" android:label=" "/> 

7) Errors will appear in the code. To fix, change:

 fptr = new IFptr();  fptr = new Fptr(); 

It will also give an error to operators containing the words "Reciept". They need to change to "Receipt".

Sample test application:

AndroidManifest file
 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ru.kkm_test"> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 


Gradle file
 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "ru.kkm_test" minSdkVersion 14 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' compile project(':fptrRes') compile files('src/main/libs/fptrproxylib.jar') compile files('src/main/libs/paycardlib.jar') compile files('src/main/libs/usblib.jar') compile files('src/main/libs/fptrlib.jar') } 


MainActivity file
 import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Toast; import com.atol.drivers.fptr.Fptr; import com.atol.drivers.fptr.IFptr; import com.atol.drivers.fptr.settings.SettingsActivity; public class MainActivity extends AppCompatActivity { IFptr fptr = null; public String TAG = "atol"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); try{ fptr = new Fptr(); fptr.create(this); } catch (NullPointerException ex){ fptr = null; } } public void onClick(View view){ switch (view.getId()){ case R.id.button: Intent intent = new Intent(this, SettingsActivity.class); intent.putExtra(SettingsActivity.DEVICE_SETTINGS, fptr.get_DeviceSettings()); startActivityForResult(intent, 1); break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == 1){ if(data!=null && data.getExtras()!=null){ String settings = data.getExtras().getString(SettingsActivity.DEVICE_SETTINGS); Toast.makeText(this, settings, Toast.LENGTH_LONG).show(); printSlip(settings); } } } @Override protected void onDestroy() { super.onDestroy(); fptr.destroy(); } public void printSlip(String settings){ if(fptr == null) { try { fptr = new Fptr(); fptr.create(this); } catch (NullPointerException ex) { fptr = null; } } fptr.put_DeviceSettings(settings); fptr.put_DeviceEnabled(true); fptr.Beep(); Log.d(TAG, fptr.GetStatus()+" status"); fptr.put_UserPassword("30"); fptr.put_Mode(1); if(fptr.SetMode()<0){ Log.d(TAG, ": "+ fptr.get_ResultCode()); } fptr.BeginDocument(); fptr.put_Caption("..."); fptr.put_ReceiptLinespacing(255); fptr.put_ReceiptBrightness(15); fptr.put_Alignment(2); fptr.PrintString(); fptr.EndDocument(); fptr.put_Mode(2); fptr.SetMode(); fptr.PrintFooter(); } } 


Next, we work on the official manual.

So let me leave. I hope someone will save time and nerves. If someone has comments and prompts, with great pleasure I will listen to them.

PS: I recently got the opportunity to test my application on a device with API23. When creating and reading a file, it constantly caught an exception. So I faced a new security policy regarding permissions. A wonderful article from OneeL : Android runtime permissions helped me figure this out . Why, why and how .

Having estimated that the capabilities of API23 in my application seem to be useless, I lowered targetSdkVersion to 22. In this case, everything began to work fine.

UPD:
Links for downloading new drivers (as of January 30, 2017):
Download Center
Archive with used drivers

Source: https://habr.com/ru/post/320624/


All Articles