intent对于电话和浏览器调用

WBOY
풀어 주다: 2016-06-07 16:10:31
원래의
1324명이 탐색했습니다.

1、创建xml文件及按钮LinearLayout xmlns:android=http://schemas.android.com/apk/res/androidandroid:orientation=verticalandroid:layout_width=match_parentandroid:layout_height=match_parentButtonandroid:id=@+id/intentbtnandroid:layout_width=fil

1、创建xml文件及按钮

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/intentbtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="intent调用浏览器"


android:layout_marginTop="100dp"/>
<Button
android:id="@+id/intentbtncall"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="intent调用电话"/>
</LinearLayout>

2、新创建一个Intent的java文件

ublic class Intent_s extends Activity {

//定义两个属性
private Button mbutton,callbutton;


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

//初始化属性
mbutton = (Button) findViewById(R.id.intentbtn);
callbutton=(Button)findViewById(R.id.intentbtncall);

//监听intent调用电话的按钮
callbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//标示地址
Uri uri = Uri.parse("tel:13881715535");

//新创建intent调用
Intent it = new Intent(Intent.ACTION_DIAL, uri);

//启动
startActivity(it);
}
});

//监听intent调用浏览器的监听
mbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//标示地址
Uri uri = Uri.parse("http://www.baidu.com");

//新创建intent
Intent intent = new Intent();

//调用intent
intent.setAction(Intent.ACTION_VIEW);

//向intent放入数据
intent.setData(uri);

//启动
startActivity(intent);
}
});
}

로그인 후 복사

 

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!