codenameone - How to test an Android native code snippet with Codename One? -


first off used programming java that's why using codename 1 develop mobile applications.

however see code in android "format" interested on testing. know how set basic native interface codename 1 tutorial.

for example, test snippet real time sound processing. involves initializing variable in android oncreate() method data available in method such am = (audiomanager) this.getsystemservice(context.audio_service); use of this has not same reference in codename 1 native interface. maybe don't have use oncreate() method (which be reached codename one) not android guru (nor cn1 1 either!), don't know.

consequently changes have make test native android code in codename 1 native interface ? maybe there methodology glad hear of.

edit solved : code used in native interface implementation works

here codename 1 native interface implementation of original android code. indeed android oncreate() method has not been used things initialized in have been transfered in initrecordandtrack() method called when suited in codename one's form. uses same method described below @akash replacing this com.codename1.impl.android.androidnativeutil.getactivity().

import android.media.audioformat; import android.media.audiomanager; import android.media.audiorecord; import android.media.audiotrack; import android.media.mediarecorder; import android.media.mediaplayer; import android.content.context;  public class kestudisnativeinterfaceimpl {  boolean isrecording = false; audiomanager = null; audiorecord record = null; audiotrack track = null;  public void initrecordandtrack() {     android.app.activity ctx = com.codename1.impl.android.androidnativeutil.getactivity();      = (audiomanager) ctx.getsystemservice(context.audio_service);     am.setspeakerphoneon(true);     int min = audiorecord.getminbuffersize(8000, audioformat.channel_in_mono, audioformat.encoding_pcm_16bit);     record = new audiorecord(mediarecorder.audiosource.voice_communication, 8000, audioformat.channel_in_mono, audioformat.encoding_pcm_16bit,             min); //    if (acousticechocanceler.isavailable()) //    { //        acousticechocanceler echocancler =  acousticechocanceler.create(record.getaudiosessionid()); //        echocancler.setenabled(true); //    }     int maxjitter = audiotrack.getminbuffersize(8000, audioformat.channel_out_mono, audioformat.encoding_pcm_16bit);     track = new audiotrack(audiomanager.mode_in_communication, 8000, audioformat.channel_out_mono, audioformat.encoding_pcm_16bit, maxjitter,             audiotrack.mode_stream);      (new thread() {         @override         public void run() {             recordandplay();         }     }).start(); }  public void startrecordandplay() {     record.startrecording();     track.play();     isrecording = true; }  public void stoprecordandplay() {     record.stop();     track.pause();     isrecording = false; }  private void recordandplay() {     short[] lin = new short[1024];     int num = 0;     am.setmode(audiomanager.mode_in_communication);     while (true) {         if (isrecording) {             num = record.read(lin, 0, 1024);             track.write(lin, 0, num);         }     } }  public boolean issupported() {     return true; } 

}

thanks lot,

cheers

have @ link https://www.codenameone.com/how-do-i---access-native-device-functionality-invoke-native-interfaces.html

in android this refer context , access context in cn1 can replace this com.codename1.impl.android.androidnativeutil.getactivity()

hope helps


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -