AppInventor2|Robot Forum 机器人开发交流平台  
  
View: 217|Reply: 5

How to Write Extensions

[Copy link]
  • TA的每日心情
    开心
    2017-7-17 23:27
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    27

    Threads

    39

    Posts

    245

    Credits

    管理员

    Rank: 9Rank: 9Rank: 9

    Credits
    245
    Post time 2017-3-12 00:58:56 | Show all posts |Read mode
    HOW TO CREATE AN EXTENSION FOR APPINVENTOR2

    Hi! I am Qiang, Wei,a high school student from China.I've made many extensions for appinventor2 which are shared in my homepage,but I would rather to share the process I made them.Sometimes, I am very busy in my school work, so I may not respond email immediately.I will respond you as soon as I can. I set up this website not for a long time,and I do very appreciate your support.


    Forum 论坛


    Tools you will need:
    1.Git Bash(a software for download git code sources)
    2.JDK(java 7)
    3.a java code editor(Jedit,EditPlus,etc)
    4.basic java programming experience
    5.Apache ant(a software for complie extensions)


    ​​​2.Install apache ant(click to Download)


    set environmental viables:
    ANT_HOME to your install path

    and add :
    your install path of ant+"\bin" to "Path"
    your install path of ant+"\lib" to "ClassPath"



    4.Start to create an extension
    -Download the appinventor sources at github and decompress it.
    -create a txt file and type in:
    ant extensions
    read
    -Then,save it with name XXX.sh in /appinventor file

    use the java code editor to establish a new file
    -the first code you must add is the "package" line.
    for example      
        package com.WeiWei.mail; //this is a pakage line,you can add a name for your file.

    -after you write package code,you need to import external class.

    code:
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////
    package com.XX;

    ////////////////////////////////////////////LET'S START TO IMPORT FILE//////////////////////////////////////
    import android.content.Context;      
    import android.util.Log;  
    import com.google.appinventor.components.annotations.*;
    import com.google.appinventor.components.common.ComponentCategory;
    import com.google.appinventor.components.runtime.*;
    import com.google.appinventor.components.runtime.collect.Sets;
    import com.google.appinventor.components.runtime.util.BoundingBox;
    import com.google.appinventor.components.runtime.util.ErrorMessages;
    import com.google.appinventor.components.runtime.util.FileUtil;
    import com.google.appinventor.components.runtime.util.MediaUtil;
    import com.google.appinventor.components.runtime.util.PaintUtil;
    import com.google.appinventor.components.common.ComponentConstants;
    import com.google.appinventor.components.common.PropertyTypeConstants;
    import com.google.appinventor.components.common.YaVersion;

    //the following file is the basic functional files for AppInventor.

    3.Create a class and add annotations.

    code:
    //////////////////////////annotations for basic initialization////////////////////////////////////
    @DesignerComponent(version = mail.VERSION,                           
        description = "",                                                        //this is your extension's description
        category = ComponentCategory.EXTENSION,     //the category is extension                          
        nonVisible = true,                                                        //only can be nonvisible        
        iconName = "XXX.jpg")                                              //picture path
    @SimpleObject(external = true)     
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public class XXX extends AndroidNonvisibleComponent    //set your class name in XXX for replacement.
    implements Component {                                          
        public static final int VERSION = 0;                                          //version number
        private ComponentContainer container;                               //define the component
        private Context context;                                                            //define the context
        private static final String LOG_TAG = "mail";                      //modify "mail" to your extension name
        public mail(ComponentContainer container) {         
            super(container.$form());                                
            this.container = container;                              
            context = (Context) container.$context();                      //define the context         
            Log.d(LOG_TAG, "mail Created" );                                 //record
        }
    ////////////////////////////////////////////add your code here//////////////////////////////////////////////////////////
    ///////////////////choose one or both of the following way//////////////////////////////////////////////////////////////
    @SimpleFunction(description = "")//annotation you must add in order to appear in appinventor as a function
    public int plus(int a,int b)
    {
    return a+b;
    }

    @SimpleProperty(description = "")//annotations you must add in order to appear in appinventor as an setable characteristics
    public boolean abc(int a,int b)
    {
    if (a ==b){
    return ture;
                    }else
    {return false;}
    }
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    }



    觉得不错?打赏下吧,1元不嫌少,10元不嫌多!
    Reply

    Use magic Report

  • TA的每日心情
    开心
    2017-7-17 23:27
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    27

    Threads

    39

    Posts

    245

    Credits

    管理员

    Rank: 9Rank: 9Rank: 9

    Credits
    245
     Author| Post time 2017-3-12 01:05:15 | Show all posts
    good
    Reply

    Use magic Report

  • TA的每日心情
    开心
    2017-7-17 23:27
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    27

    Threads

    39

    Posts

    245

    Credits

    管理员

    Rank: 9Rank: 9Rank: 9

    Credits
    245
     Author| Post time 2017-3-12 01:05:27 | Show all posts
    good
    Reply

    Use magic Report

  • TA的每日心情
    开心
    2017-7-17 23:27
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    27

    Threads

    39

    Posts

    245

    Credits

    管理员

    Rank: 9Rank: 9Rank: 9

    Credits
    245
     Author| Post time 2017-3-18 08:31:08 | Show all posts
    questions?

    该用户从未签到

    0

    Threads

    2

    Posts

    6

    Credits

    新手上路

    Rank: 1

    Credits
    6
    Post time 2017-4-1 18:22:04 | Show all posts
    我下载了一个第三方的sdk,是个jar文件,里面是一些class文件。请问我该怎么才能import那个jar文件中的class?
  • TA的每日心情
    开心
    2017-7-17 23:27
  • 签到天数: 3 天

    [LV.2]偶尔看看I

    27

    Threads

    39

    Posts

    245

    Credits

    管理员

    Rank: 9Rank: 9Rank: 9

    Credits
    245
     Author| Post time 2017-4-1 20:49:55 | Show all posts
    wangsk789 replied at 2017-4-1 18:22
    我下载了一个第三方的sdk,是个jar文件,里面是一些class文件。请问我该怎么才能import那个jar文件中的clas ...

    将jar文件拖入appinventor lib文件夹中  需要修改appinventor的build.xm文件 加入jar的路径

    You have to log in before you can reply Login | 立即注册

    Points Rules

    Quick Reply To Top Return to the list