Uri, setAction, and setData start other programs by clicking the button:
// Use implicit Intent to start other programs private void btn2Click () // browse a webpage {intent Intent = new intent (); Intent. setAction (Intent. ACTION_VIEW); Uri data = Uri. parse ("http://www.163.com"); intent. setData (data); startActivity (intent);} private void btn1Click () // call the button to start dialing {Intent intent = new Intent (); intent. setAction (Intent. ACTION_CALL); // you need to set the permission for automatic dialing. CALL_PHONE // intent. setAction (Intent. ACTION_DIAL); // jump to the dialing interface // Uri. fromFile (file) open a file Uri data = Uri. parse ("tel: 110"); // uri identifier format of the number intent. setData (data); startActivity (intent );}
Btn1Click XML permission Configuration:
<uses-permission android:name="android.permission.CALL_PHONE"/>
You can use an implicit intent to start another project from one project:
// Use an implicit Intent to start another project private void btn1Click () {intent Intent = new intent (); // Intent. setAction ("com. example. aex60 ");/** 1. after setData, if no component in the implicit intent has a data filter set, the fc error occurs. * 2. the relationship (or relationship) between setAction and setData is set in the implicit intent. If either of the two settings is met, the setAction can be started. * 3. setData (Uri. parse ("http: //") sets this default setting to enable the browser * 4. <data android: scheme = "http" android: host = "www.163.com" android: path = "/note" mimeType = "mnt/png"/> * scheme = "http ": protocol. data is Uri. parse ("http:") * host = "www.163.com": Address * path = "/note" :( similar to) folder, which must be prefixed /. * MimeType = "mnt/png": (similar to) file type. ** Scheme, host, path, and mimeType are related to each other. ** 5. intent. setData (data); * intent. setType ("mnt/png"); * The two items cannot be written separately. You need to use setDataAndType (). ** 6. intent. addCategory ("xxxx. xxx "); this method adds a filter condition * // Uri data = Uri. parse ("http:"); // Add ":", scheme = "http" Uri data = Uri to the browser protocol. parse (" http://www.163.com/note "); // Intent. setData (data); // intent. setType ("mnt/png"); intent. setDataAndType (data, "mnt/png"); startActivity (intent );}
XML configuration for another project:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.aex60_2_intentfilter_data_componet" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.aex60_2_intentfilter_data_componet.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="com.example.aex60" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="http" android:host="www.163.com" android:path="/note" android:mimeType="mnt/png"/> </intent-filter> </activity> </application></manifest>
This article is from the "no trace in the sky but I fly over" blog. For more information, contact the author!