Giter Site home page Giter Site logo

urltoopenapp's Introduction

本代码是androidstudio编写,其中也有eclipse版本在对应的eclipse文件夹里

##效果 image

##功能 1、通过intent启动app并传值 2、通过url可以自动启动app。 3、可以通过点击短信,qq,各种浏览器加载指定的url都可以启动app并传值。

##通过intent启动并传值

            Intent intent = new Intent();
            intent.setComponent(new ComponentName("com.dalong.app2",
                    "com.dalong.app2.MainActivity"));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra("name", "lisi");
            intent.putExtra("age", "18");
            intent.setAction(Intent.ACTION_VIEW);
            startActivity(intent);

##通过scheme启动并传值

          <intent-filter>
                   <action android:name="android.intent.action.VIEW"/>
                   <category android:name="android.intent.category.DEFAULT" />
                   <category android:name="android.intent.category.BROWSABLE" />
                   <data android:scheme="dalong" android:host="my.app" android:pathPrefix="/openwith"/>
          </intent-filter>

##通过intent和scheme启动获取数据值

                  Intent intent=getIntent();
                  String name="";
                  String age="";
                  if(intent!=null){
                      /**************通过intent启动*******************/
                      name=intent.getStringExtra("name");
                      age=intent.getStringExtra("age");
                      String action = intent.getAction();
          
                      /**************通过scheme 启动*******************/
                      if(Intent.ACTION_VIEW.equals(action)){
                          Uri uri = intent.getData();
                          if(uri != null){
                               name = uri.getQueryParameter("name");
                               age= uri.getQueryParameter("age");
                          }
                      }
                      textView.setText(name+"\n"+age);
                  }

urltoopenapp's People

Contributors

yixiaolunhui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  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.