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 学習者の迅速な成長を支援します!