[mono-android] JNI Help Please

digitalml matthew.lebo at stationcasinos.com
Sat Jan 14 01:05:25 UTC 2012


I'm trying to implement a 3rd party jar file to read credit cards and I'm
having issues. All JNI examples I've found either return an activity or use
static methods and mine is not static and not really an activity I want to
show on the screen. I want to call these methods of this class via JNI
through MonoDroid

I'd like to be able to call the InitializeReader() method, the SwipeCard()
method and listen for the callback onReceiveMsgCardData() all through JNI

Here is the .java file im using, it compiles fine...
---------------------------------------------------------
import IDTech.MSR.uniMag.uniMagReader;
import IDTech.MSR.uniMag.uniMagReaderMsg;
import android.app.Activity;

public class jni_helper extends Activity implements uniMagReaderMsg {
	private uniMagReader myUniMagReader = null ; 

    private jni_helper()
    {
	}
    	
	public void InitializeReader()
	{
		if(myUniMagReader == null)
			myUniMagReader =  new uniMagReader(this, this);
		myUniMagReader.setVerboseLoggingEnable(false);
        myUniMagReader.registerListen();
	}

	public void SwipeCard()
	{
		if(myUniMagReader!=null)
			myUniMagReader.startSwipeCard();
	}

	public String _strMSRData = null;
	private byte[]_MSRData = null;

	public void onReceiveMsgCardData(byte flagOfCardData,byte[] cardData) 
	{
		byte flag = (byte) (flagOfCardData&0x04);
	 
		if(flag==0x00)
			_strMSRData = new String (cardData);
		if(flag==0x04)
		{
			_strMSRData = new String (cardData);
		}

		_MSRData = null;
		_MSRData = new byte[cardData.length];
		System.arraycopy(cardData, 0, _MSRData, 0, cardData.length);
	}

	public void onReceiveMsgConnected() 
	{

	}

	public void onReceiveMsgDisconnected() 
	{

	}

	public void onReceiveMsgTimeout(String strTimeoutMsg) 
	{

	}

	public void onReceiveMsgToConnect()
	{ 
	
	}

	public void onReceiveMsgToSwipeCard() 
	{

	}

	public void onReceiveMsgSDCardDFailed(String strSDCardFailed)
	{

	}

	public boolean getUserGrant(int type, String strMessage) 
	{
		return true;
	}

	public void onReceiveMsgFailureInfo(int index, String strMessage) 
	{
	
	}
}

And here is my .Net helper class to call the JNI. It errors at the
JNIEnv.CallVoidMethod()
----------------------------------------------------------------------------------------

 public static class MagHelper
    {
        private static IntPtr _helperClass =
JNIEnv.FindClass("Stations/MagHelper/jni_helper");
        public static void InitializeReader()
        {
            IntPtr methodId = JNIEnv.GetMethodID(_helperClass,
"InitializeReader", "()V");
            if (null != methodId)
                JNIEnv.CallVoidMethod(_helperClass, methodId);
        }
    }

Any help or pointers would be appreciated.

Thanks
DML

--
View this message in context: http://mono-for-android.1047100.n5.nabble.com/JNI-Help-Please-tp5144171p5144171.html
Sent from the Mono for Android mailing list archive at Nabble.com.


More information about the Monodroid mailing list