安卓隐式intent(打电话,浏览器)


1.知识图谱:



1.xml文件

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.cookie.android0619intent.MainActivity">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="跳B"
        android:textSize="30sp"
        android:onClick="jumpB"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="打电话"
        android:onClick="callPhone"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="百度一哈"
        android:onClick="baidu"/>

</LinearLayout>



activity_b.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.cookie.android0619intent.BActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="这是洒家的浏览器"
        android:textSize="30sp"
        android:background="#6600"/>

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/wv_web"
        ></WebView>

</LinearLayout>


JAVA代码:

MainActivity.java

package com.example.cookie.android0619intent;

import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

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

    }

    public void jumpB(View view){
        //显式Intent
        Intent intent=new Intent();
        //设置要跳转的组件的名字
        ComponentName componentName=new ComponentName(this,BActivity.class);
        intent.setComponent(componentName);
        startActivity(intent);

        //隐式Intent
    }

    public void callPhone(View view){
        Intent intent=new Intent();
        //跳到一个视图
        intent.setAction(Intent.ACTION_VIEW);
        //指定数据
        intent.setData(Uri.parse("tel:13539407043"));
        startActivity(intent);
    }

    public void baidu(View view){
        Intent intent=new Intent();
        //跳一个系统的视图
        intent.setAction(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("http://www.baidu.com"));
        startActivity(intent);
    }

}


BActivity.java

package com.example.cookie.android0619intent;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class BActivity extends AppCompatActivity {

    private WebView wv_web;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_b);
        wv_web = (WebView) findViewById(R.id.wv_web);
        //接收main页面界面传递过来的数据(网址)
        String path=getIntent().getDataString();

        //让wv_web加载网址
        wv_web.loadUrl(path);

        //设置使用自己的wv_web客户端打开网址
        wv_web.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }
}








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值