GithubHelp home page GithubHelp logo

msdgwzhy6 / cordova-plugins-activity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fomenyesu/cordova-plugins-activity

1.0 2.0 0.0 220 KB

cordova调用安卓原生activity插件

Java 90.63% JavaScript 9.37%

cordova-plugins-activity's Introduction

cordova-plugins-activity

cordova调用安卓原生activity插件

###使用简介 JS端使用方式

//sendData表示要从js端发送到原生activity的数据,需用json对象传输
var sendData = {
  id:10001,
  name:"Simon",
  age:28
};
window.cordova.plugins.activity.start("com.zlzkj.vendor.MyActivity",sendData,function(data){
    //回调函数中的data表示从原生activity传回来的数据,已处理为json对象
    alert(data.id+"::"+data.name);
});

原生安卓activity接收参数和回传参数简单示例

public class MyActivity extends Activity {

    private Button btn;

    private int flag = 0;

    private Intent intent = null;

    private Context context = this;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.my_activity_main);

        intent = getIntent();

        String userId = intent.getStringExtra("id");
        String userName = intent.getStringExtra("name");
        String userAge = intent.getStringExtra("age");

        btn = (Button) findViewById(R.id.button_back);
        TextView tv = (TextView) findViewById(R.id.textView);
        tv.setText(userId+"::"+userName+"::"+userAge);

        btn.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent mIntent = new Intent();
                mIntent.putExtra("id", "10003");
                mIntent.putExtra("name", "Jackson");
                // 设置结果,并进行传送
                setResult(RESULT_OK, mIntent);
                finish();
            }
        });

    }

}

cordova-plugins-activity's People

Contributors

cfansimon avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.