Android opens its own APP (scheme) through the web page, androidscheme

Source: Internet
Author: User

Android opens its own APP (scheme) through the web page, androidscheme

You can access a webpage through a browser (built-in or third-party) on your mobile phone. You can click a link to start your application and transmit data.

First, add a filter to the Activity to be started in the Mainifest file.

<activity            android:name="com.example.helloworld.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>            <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="znn"/>            </intent-filter>        </activity>

Receive data in MainActivity:

public class MainActivity extends Activity implements View.OnClickListener{@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Intent intent = getIntent();String scheme = intent.getScheme();Uri uri = intent.getData();System.out.println("scheme:"+scheme);if (uri != null) {String host = uri.getHost();String dataString = intent.getDataString();String id = uri.getQueryParameter("id");String path = uri.getPath();String path1 = uri.getEncodedPath();String queryString = uri.getQuery();System.out.println("host:"+host);System.out.println("dataString:"+dataString);System.out.println("id:"+id);System.out.println("path:"+path);System.out.println("path1:"+path1);System.out.println("queryString:"+queryString);}}}


Write a simple webpage:

<a href="znn://aa.bb:80/test?p=12&d=1">test</a>



Test URL: www.erdian.net/m.html

Test results:

Scheme: znn
Host: aa. bb
DataString: znn: // aa. bb: 80/test? P = 12 & id = 1
Id: 1
Path:/test
Path1:/test

QueryString: p = 12 & d = 1


Http://www.erdian.net /? P = 238


Android Application Development: the first time an app is opened, it is a login page. After login, the page is directly displayed on the home page. How to Design the page relationship of the app?

1. You can use SharedPreferences to record the login status...
2. You can use the same Activity on the home page and login page, but use different layout files, such as main. xml and login. xml.
3. When the first Activity is started, in the onCreate method, first obtain the login status in SharedPreference. Assume that it is a Boolean isLogin.
If (isLogin) {setContenView (R. layout. main );.........} else {setContenView (R. layout. login );.........} welcome to question ~ Hope to adopt ~


Create an APP on the Android mobile phone and open the URLs between companies in the form of a browser. Ask what controls are used in the navigation bar below?

You can use View to write one, and then add the buttons one by one on it!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.