PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile (précédentes versions) → java import d'un fichier aidl
java import d'un fichier aidl
Débuté par Philippe Pasquali, 15 nov. 2016 14:14 - 6 réponses
Membre enregistré
945 messages
Popularité : +102 (110 votes)
Posté le 15 novembre 2016 - 14:14
Bonjour,
Je tente d'adapter un code java en Windev Mobile 20 (c'est pour utiliser une imprimante intégrée au smartphone : CITAQ SUNMI V1-G)

Comment traduire ?
import woyou.aidlservice.jiuiv5.ICallback;
import woyou.aidlservice.jiuiv5.IWoyouSe;

sachant que dans un répertoire : \woyou\aidlservice\jiuiv5 je trouve deux fichiers : ICallback et IWoyouSe avec une extension "AIDL" (j'ai les même fichiers avec une extention .class et .java)

Voici l'ensemble de l'unique code d'exemple java en ma possession
package com.citaq.v5print;

import woyou.aidlservice.jiuiv5.ICallback;
import woyou.aidlservice.jiuiv5.IWoyouSe;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

PUBLIC class MainActivity extends Activity {

Button bt_print;
Button bt_print_portugal;
EditText et_text;

PROTECTED static final string TAG = null;
IWoyouService woyouService;

@Override
PROTECTED void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Intent intent = new Intent();
intent.setPackage("woyou.aidlservice.jiuiv5");
intent.setAction("woyou.aidlservice.jiuiv5.IWoyouService");
startService(intent);
bindService(intent, connService, Context.BIND_AUTO_CREATE);

printTexte("maman va au marché");

init();
}

PRIVATE void init(){
bt_print = (Button) findViewById(R.id.bt_print);
bt_print_portugal = (Button) findViewById(R.id.bt_print_portugal);
et_text = (EditText) findViewById(R.id.et_text);

bt_print.setOnClickListener(new OnClickListener() {
@Override
PUBLIC void onClick(View arg0) {
printTexte(et_text.getText().toString());
}
});

bt_print_portugal.setOnClickListener(new OnClickListener() {
@Override
PUBLIC void onClick(View arg0) {
printTexte("A nação Chinesa desde OS tempos antigos,é um defensor Da paz.");
}
});
}

PRIVATE void printTexte(string str){
try {
woyouService.printText(str+"\n",callback);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (EXCEPTION e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


PRIVATE ServiceConnection connService = new ServiceConnection() {
@Override
PUBLIC void onServiceDisconnected(ComponentName name) {
woyouService = null;
}
@Override
PUBLIC void onServiceConnected(ComponentName name, IBinder service) {
woyouService = IWoyouService.Stub.asInterface(service);
try {
woyouService.printerInit(callback) ; // 注册回调函数
} catch (RemoteException e) {
Log.d(TAG, "registerCallback failed.");
}

}
};

PRIVATE ICallback callback = new ICallback.Stub() {
@Override
PUBLIC void onRunResult(boolean isSuccess) throws RemoteException {
// TODO Auto-generated method stub
Log.d(TAG, "ICallback--->" + isSuccess);
}

@Override
PUBLIC void onReturnString(string RESULT) throws RemoteException {
// TODO Auto-generated method stub
Log.d(TAG, "ICallback--->" + RESULT);
}

@Override
PUBLIC void onRaiseException(int code, string msg)
throws RemoteException {
Log.d(TAG, "onRaiseException--->" + msg);
}
};

@Override
PROTECTED void onPause() {
// TODO Auto-generated method stub
super.onStop();
}
}


ps
je suis nul en java.....
Membre enregistré
945 messages
Popularité : +102 (110 votes)
Posté le 16 novembre 2016 - 20:10
bonsoir
Après de pénibles recherche, je suis toujours au point mort car je ne voit pas comment dire à Windev Mobile, d'aller chercher dans
D:\Mes Projets Mobile V20\Bus\V5Print\bin\classes\woyou\aidlservice\jiuiv5 les fichiers utiles pour exécuter :

import woyou.aidlservice.jiuiv5.IWoyouService;
import woyou.aidlservice.jiuiv5.ICallback;

Modification de CLASSPATH, copie du répertoire V5Print dans différents endroits du répertoire où est installé android-sdk, rien n'y fait...
Personne n'a utilisé de class (non incluse en standard dans android) dans Windev mobile ?

Liste des sous-répertoires de D:\Mes Projets Mobile V20\Bus\V5Print :




Contenu du répertoire : D:\Mes Projets Mobile V20\Bus\V5Print\bin\classes\woyou\aidlservice\jiuiv5 :




Un grand merci d'avance à celui ou celle, qui me donnera la solution...(si elle existe)
Membre enregistré
945 messages
Popularité : +102 (110 votes)
Posté le 18 novembre 2016 - 17:06
RESOLU (en partie))
"Une" solution, au moins, existe... mais c'est tiré par les cheveux...en résumé c'est :
1) compiler avec windev mobile et récupérer la ligne de commande utilisée pour compiler
2) copier les classes et autres fichiers dans "<Disque>:\Mes Projets Mobile\<project name>\Android\Generation\bin\classes\"car la compil Windev efface ce répertoire
3) avec une commande dos lancer manuellement la compil en utilisant ce que l'on a récupéré en 1er
si on recompil avec Windev «sans modifier le source» alors il va télécharger l'apk dans le terminal

si il y a plus simple je suis preneur....
Posté le 06 juillet 2017 - 13:12
HI, did you resolve the problem to import woyou lib? I have the same problem, I don´t know where to place it to import into the project. I obtain this error when compile

Command Line: "C:\Program Files\Java\jdk1.8.0_131\bin\java.exe" "-Dorg.gradle.appname=C:\My Mobile Projects\Backup_PrintBluetooth_2016-06-27\Android\Generation" -classpath "C:\WINDEV Mobile 22\Personal\Android\Gradle\lib\gradle-launcher-2.14.1.jar" org.gradle.launcher.GradleMain assembleDebug -b "C:\My Mobile Projects\Backup_PrintBluetooth_2016-06-27\Android\Generation\build.gradle"


Error returned:

:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
C:\My Mobile Projects\Backup_PrintBluetooth_2016-06-27\Android\Generation\src\com\mycompany\printbluetooth\wdgen\GWDCPTSCPrint.java:18: error: package woyou.aidlservice.jiuiv5 does not exist
import woyou.aidlservice.jiuiv5.IYmodemSPI;
^
C:\My Mobile Projects\Backup_PrintBluetooth_2016-06-27\Android\Generation\src\com\mycompany\printbluetooth\wdgen\GWDCPTSCPrint.java:19: error: package woyou.aidlservice.jiuiv5 does not exist
import woyou.aidlservice.jiuiv5.IWoyouSe;
^
C:\My Mobile Projects\Backup_PrintBluetooth_2016-06-27\Android\Generation\src\com\mycompany\printbluetooth\wdgen\GWDCPTSCPrint.java:20: error: package woyou.aidlservice.jiuiv5 does not exist
import woyou.aidlservice.jiuiv5.ICallback;
^
3 errors
:compileDebugJavaWithJavac FAILED
Membre enregistré
945 messages
Popularité : +102 (110 votes)
Posté le 06 juillet 2017 - 15:27
Hi,
I did not find a solution, then I wrote in java a program that at launch, test if there exists a file to print.
If the file exists it is printed, killed and the application closes.
The Windev Mobile program creates the file with the data to be printed and starts the java program.
I know this is not the best solution but it works...

*******************************************
* Windev Mobile function
*******************************************
//-------------------------------------------------------------------------------------- 
// Cette procédure écrit les données à imprimer dans le fichier echange.txt dans
// le répertoire \storage\emulated\0\ du smartphone
// Ce fichier sera automatiquement imprimé et supprimé par le programme V5Print.
// Date   : Novembre-2016
//-------------------------------------------------------------------------------------- 
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public static void SaveToPrintFile(String sDataFile)
{
File sdLien = Environment.getExternalStorageDirectory();
File monFichier = new File(sdLien, "echange.txt");

//----- Si le fichier existe on le supprime sinon l'écriture ne fonctionnera pas !
if (monFichier.exists()) {
//----- Suppression du fichier
monFichier.delete();


BufferedWriter writer = null;       
try {
//----- il se trouve stocké dans : \storage\emulated\0\echange.txt
FileWriter out = new FileWriter(monFichier);
writer = new BufferedWriter(out);         
writer.write(sDataFile);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}


*******************************************
Windev Mobile
*******************************************
//-------------------------------------------------------------------------------------- 
// Cette procédure permet de lancer le programme d'impression V5Print écrit en java. 
// le fichier texte à imprimer sera créé au préalable par la procédure SaveToPrintFile()
// Date   : Novembre-2016
//-------------------------------------------------------------------------------------- 
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;

public static void LanceV5Print()
{
Activity act = getActiviteEnCours();
act.startActivity(act.getPackageManager().getLaunchIntentForPackage("com.citaq.v5print")); 
}


*******************************************
JAVA code (base code V5Print)
*******************************************
package com.citaq.v5print;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import woyou.aidlservice.jiuiv5.ICallback;
import woyou.aidlservice.jiuiv5.IWoyouService;

// pour visualiser les messages mis dans le log avec Log.d
// dans une fenêtre MsDos, se positionner dans le répertoire du SDK Android
// C:\Program Files (x86)\Android\android-sdk\platform-tools>
//  et exécuter : adb -d logcat V5Print:D *:S
// V5Print correspond au String TAG
// D  correspond au Log.d()

//----- start of Activity
public class MainActivity extends Activity {

Button bt_printFile;

String sDataFile;
String ligne;
String ReadBuffer = "";
protected static final String TAG = "V5Print";
IWoyouService woyouService;

//------------------------------------------------------------------------- onPause
@Override
protected void onPause() {
Log.d(TAG, "onPause()");
super.onStop();
}

//------------------------------------------------------------------------- onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Log.d(TAG, "Start of OnCreate()");
Intent intent = new Intent();
intent.setPackage("woyou.aidlservice.jiuiv5");
intent.setAction("woyou.aidlservice.jiuiv5.IWoyouService");
startService(intent);
bindService(intent, connService, Context.BIND_AUTO_CREATE);

init(); // Initialisation du bouton pour qu'il execute PrintData

//Log.d(TAG, "Execution de PrintData() dans OnCreate()");
//PrintData(); //fichier echange.txt supprimé mais pas d'impression

Log.d(TAG, "End of OnCreate()");
}

//-------------------------------------------------------------------------Impression
// @Override
// protected void onStart(){
// Log.d(TAG, "onStart");
// }

//-------------------------------------------------------------------------Impression
private void PrintData() {
Log.d(TAG, "Start of PrintData()");

File sdLien = Environment.getExternalStorageDirectory();
        File monFichier = new File(sdLien + "/echange.txt");
        
        if ( monFichier.exists()) {
         Log.d(TAG, "echange.txt found.");
         try {
         //----- Lecture du fichier d'échange
         Log.d(TAG, "OPEN echange.txt");
         BufferedReader fichier = new BufferedReader(new FileReader(monFichier));
         while ((ligne = fichier.readLine()) != null) {
         ReadBuffer = ReadBuffer + ligne + "\n";
         }
         //----- Fermeture et suppression du fichier d'échange
         Log.d(TAG, "CLOSE echange.txt");
         fichier.close();
         Log.d(TAG, "DELETE echange.txt");
         monFichier.delete();
         } catch (Exception e) {
         Log.d(TAG, "Erreur OPEN/CLOSE/DELETE echange.txt");
         e.printStackTrace();
         }
        
         if (ReadBuffer != "") { 
                //-----Impression
         try {
         Log.d(TAG, "Start of print." + "\n" + ReadBuffer);
         woyouService.printText(ReadBuffer + "\n", callback);
         Log.d(TAG, "End of print. Bye Bye" + "\n");
         //----- Bye Bye...
                 // System.exit(0);   // Très déconseillé (je ne sais pas pourquoi)
                  android.os.Process.killProcess(android.os.Process.myPid());
                 //finish();
         } catch (RemoteException e) {
         Log.d(TAG, "Erreur RemoteException woyouService.printText");
         e.printStackTrace();
         } catch (Exception e) {
         Log.d(TAG, "Erreur Exception woyouService.printText");
         e.printStackTrace();
         }
         } // End if
         else
         {
         Log.d(TAG, "echange.txt is empty ! (bye bye)");
                //----- Bye Bye...
                // System.exit(0);   // Très déconseillé (je ne sais pas pourquoi)
                 android.os.Process.killProcess(android.os.Process.myPid());
                //finish();
         }
        } // End if

        //----- le fichier n'existe pas alors Bye Bye...
        Log.d(TAG, "echange.txt not found... Bye Bye");
        // System.exit(0);   // Très déconseillé (je ne sais pas pourquoi)
        // android.os.Process.killProcess(android.os.Process.myPid());
        finish();
}



//------------------------------------------------------------------------- Initialisation
private void init(){
Log.d(TAG, "Start of init()");
//--------------------------------------------------------------------- Bouton printFile
bt_printFile = (Button) findViewById(R.id.bt_PrintFile);
bt_printFile.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Log.d(TAG, "Execution de PrintData() dans onClick()");
PrintData();
   } // End onClick
}); // End bt_printFile.setOnClickListener
Log.d(TAG, "End of init()");
} // end of init()



//-------------------------------------------------------------------------
private ServiceConnection connService = new ServiceConnection() {

@Override
public void onServiceDisconnected(ComponentName name) {
Log.d(TAG, "onServiceDisconnected()");
woyouService = null;
} // End onServiceDisconnected()

@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.d(TAG, "onServiceConnected()");
woyouService = IWoyouService.Stub.asInterface(service);
try {
Log.d(TAG, "woyouService.printerInit");
woyouService.printerInit(callback);
PrintData();
} catch (RemoteException e) {
Log.d(TAG, "registerCallback failed.");
}
} // End onServiceConnected()

}; // End connService

//-------------------------------------------------------------------------
private ICallback callback = new ICallback.Stub() {

@Override
public void onRunResult(boolean isSuccess) throws RemoteException {
Log.d(TAG, "onRunResult-ICallback--->" + isSuccess); 
}

@Override
public void onReturnString(String result) throws RemoteException {
Log.d(TAG, "onReturnString-ICallback--->" + result); 
}

@Override
public void onRaiseException(int code, String msg) throws RemoteException {
Log.d(TAG, "onRaiseException-ICallback--->" + msg);
}

}; // End callback

} // End Activity
Posté le 26 août 2017 - 17:51
Hi, excuse I was not ON during 1 month. I will test. A lot of thanks.
Membre enregistré
1 message
Posté le 26 août 2017 - 19:53
I also are nul in Java, I only work with Windev for a month more or less.

Two way triying to print:

Bluettoth printing
I tried to connect with sunny printer (InnerPrinter) via bluettoth, I obtain connection, but when I send the data to the buffer, the printer do "nothing", not print, but the program don´t send to me error. It seems it´s ok.

AIDL printing
I can´t found where to place this
import woyou.aidlservice.jiuiv5.ICallback;
import woyou.aidlservice.jiuiv5.IWoyouService;

I copy to \generation\....etc, but the system say me "directory not empty". Really stopped...uhmmm

Regards. Jose Luis

--
Mercie. Thanks. Gracias. redes@adip.net