你的位置:首页 > 操作系统

[操作系统]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);
//权限设置如下
<?<manifest   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();
}