Now let see how do we create Native Extension for Android Device. Before we begin please make sure we had the tools:
- Android Studio
- Java SDK
- Air SDK (for library FlashRuntimeExtensions.jar
Now we can start the "How To"
THE "HOW TO" ^__^.
- Create a Project in Android Studio.
- Copy file FlashRuntimeExtensions.jar from air_sdk_dir\lib\android (in Air SDK) to lib in the project:
- make sure the file "build.gradle" compile the library in the dependancy
okay now our tools is wraped and zipped zap zip zup dzig!
Next we create "The Class"
"THE CLASS"
there is 3 class we have to create, and that is:
- Class that implements "FREExtension" Interface.
- Class that extends "FREContext" Class.
- And Class that impements "FREFunction" Interface.
public FREObject call(FREContext freContext, FREObject[] freObjects)
okay lets just call it "function" with FREObject as the return type FREObject is a Object that cunstructed from primitve object type .
boolean, double, int and String.
since AIR object is similiar with JSONObject for the complex return we use String that we construct to JSON Object for general purpose, here some JSONString sample:
String json="{\"name\" : \""+User.name+"\",\"user Id No\" : "+User.id+"}";
Result : {"name" : "subhan" , "user Id No" : 12311}
here the full FREFunction Class:
____________________________________________________________________________________________
package com.example.subhan;
import com.adobe.fre.FREContext; import com.adobe.fre.FREFunction; import com.adobe.fre.FREObject; import com.adobe.fre.FREWrongThreadException; /** * Created by Subhan on 9/6/2016. */public class GetUserInfo implements FREFunction { FREObject freObject=null; String json=null; @Override public FREObject call(FREContext freContext, FREObject[] freObjects) { try { json="{\"name\" : \""+User.name+"\",\"user Id No\" : "+User.id+"}";
freObject = FREObject.newObject(json); } catch (FREWrongThreadException e) { e.printStackTrace(); } return freObject; }
}
_____________________________________________________________________________________________
okay that it for the FREFunction, next we go to Class that Extends "FREContext" Class
in this class we have to implement getFunction <-- The Function of FREContext.
here some example of the full class:
_____________________________________________________________________________________________
package com.example.subhan;
import com.adobe.fre.FREContext; import com.adobe.fre.FREFunction;
import com.example.subhan.GetUserInfo; import java.util.HashMap; import java.util.Map; /** * Created by Subhan on 9/5/2016. */public class UserInfoContext extends FREContext { @Override public Map<String, FREFunction> getFunctions() { GetUserInfo comm = new GetUserInfo(getActivity()); Map<String, FREFunction> functions = new HashMap<String, FREFunction>(); functions.put("getUserInfo", new GetUserInfo()); return functions; } @Override public void dispose() { } }
_____________________________________________________________________________________________thats all nothing special just that function.put () is one class that implements FREFunction for each method to put in the function with string map that will invoke from ActionScript Library.
now for the last Class that implements "FREExtension" .. there is nothing special in here just implement methods of the interface:
- public void initialize().
- public FREContext createContext(String s).
- public void dispose().
_________________________________________________________________________________
package com.example.subhan; import com.adobe.fre.FREContext; import com.adobe.fre.FREExtension; /** * Created by Subhan on 9/5/2016. */public class UserInfoExtension implements FREExtension{ @Override public void initialize() { } @Override public FREContext createContext(String s) { return new UserInfoContext(); } @Override public void dispose() { } }_________________________________________________________________________________
okay done that all for the class .. hope it will help..
we have to create library for this ANE get work
this is how export jar java library with android
No comments:
Post a Comment