• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

gisoracle

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

Android Intent调用 Uri的使用几种格式

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();
}

posted on 2016-02-15 13:10  gisai  阅读(2108)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3