Android Intent calls the Uri in several formats, androidintent

Source: Internet
Author: User

Android Intent calls the Uri in several formats, androidintent

Open Baidu

Uri uri = Uri. parse ("http://www.baidu.com ");
Intent intent = new Intent (Intent. ACTION_VIEW, uri );
StartActivity (intent );

Open another page
Intent intent =new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
// Call
Uri uri = Uri. parse ("tel: 10010 ");
Intent it = new Intent (Intent. ACTION_DIAL, uri );
StartActivity (it );
// The permission settings are as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. gis_luq.activitytest1">
<Uses-permission android: name = "android. permission. CALL_PHONE"/>
<Application
Android: allowBackup = "true"
Android: icon = "@ mipmap/ic_launcher"
Android: label = "@ string/app_name"
Android: theme = "@ style/AppTheme">
<Activity
Android: name = ". MainActivity"
Android: label = "@ string/app_name">
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>

<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>
<Activity
Android: name = ". Main2Activity"
Android: label = "@ string/title_activity_main2">
</Activity>
</Application>

</Manifest>

Information Transmission
Intent intent = new Intent (MainActivity. this, Main2Activity. class );

Intent. putExtra ("yl1", "gisoracle ");

// Use Bundle to carry data
Bundle bundle = new Bundle ();
// Pass the name parameter tinyphp
Bundle. putString ("yl2", "I Love You GUI Xia ");
Intent. putExtras (bundle );
StartActivity (intent );

public class Main2Activity extends AppCompatActivity {
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main2 );

// Obtain the Intent carrying data
Intent intent = getIntent ();
String index = intent. getStringExtra ("yl1 ");

// Use Bundle to carry data
Bundle bundle = getIntent (). getExtras ();
String data = bundle. getString ("yl2"); // read data

Toast. makeText (this, index + "-" + data, Toast. LENGTH_SHORT). show ();
}

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.