Android 实例:使用Android 里的intent

Android 里的intent 比较好玩,那么什么是系统意图?就是调用个浏览器,拨号盘等等。

这个实例比较简洁,请自行脑补 or 创建 一个hello world 项目。

打开系统浏览器

编辑主 Activity 的onCreate 方法。

Intent intent = new Intent(Intent.ACTION_VIEW); 获取Android 的intent
intent.setData(Uri.parse("http://www.baidu.com")); 设置数据
startActivity(intent); 开始个intent

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button b = (Button) findViewById(R.id.button1);
        b.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("http://www.baidu.com"));
                startActivity(intent);
            }
        });

    }

自己创建个打开方式

如何自己创建个intent, 当用户点击一个http请求时,会启动我们的Activity。

很简单其实将我们自己的Activity 添加个过滤就可以,只要程序在运行,用户只要符合过滤的就能够激活我们的活动。

AndroidManifest.xml <Activity>...</Activity>
<action android:name="android.intent.action.VIEW"/> 指定一个intent 的打开系统Intent(可多个)
<category android:name="android.intent.category.DEFAULT"/> 指定个类别(可多个)
<data android:scheme="http"/> 指定打开方式(可多个)

<intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:scheme="http"/>
                <data android:scheme="https"/>

</intent-filter>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值