Android Intent調用 Uri的使用幾種格式
打開百度
Uri uri = Uri.parse("http://www.baidu.com");
Intent intent =new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
打開另一個頁面
Intent intent =new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
//撥打電話
Uri uri = Uri.parse("tel:10010");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
//許可權設置如下
<?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>
傳達信息
Intent intent =new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("yl1","gisoracle");
//用Bundle攜帶數據
Bundle bundle=new Bundle();
//傳遞name參數為tinyphp
bundle.putString("yl2", "我愛你桂霞");
intent.putExtras(bundle);
startActivity(intent);
public class Main2Activity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
//獲取Intent攜帶數據
Intent intent = getIntent();
String index = intent.getStringExtra("yl1");
//用Bundle攜帶數據
Bundle bundle = getIntent().getExtras();
String data = bundle.getString("yl2");//讀出數據
Toast.makeText(this, index + "-" + data, Toast.LENGTH_SHORT).show();
}