Intent的几个基本事件
来源:互联网 发布:java根据模板生成pdf 编辑:程序博客网 时间:2024/05/21 19:29
在xml添加几个按钮
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:text="打电话给小呆呆"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" android:text="给小呆发信息"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button3" android:text="不理小呆,去百度"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button4" android:text="不理小呆,看地图"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button5" android:text="想想要不要给小呆打电话"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button6" android:text="听歌曲"/></LinearLayout>
在main中的代码
package com.example.com;import java.util.ArrayList;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.telephony.SmsManager;import android.view.View;import android.widget.Button;import android.widget.Toast;public class MainActivity extends Activity { Button button1,button2,button3,button4,button5,button6; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button1=(Button) findViewById(R.id.button1); button2=(Button) findViewById(R.id.button2); button3=(Button) findViewById(R.id.button3); button4=(Button) findViewById(R.id.button4); button5=(Button) findViewById(R.id.button5); button6=(Button) findViewById(R.id.button6); button1.setOnClickListener(listener); button2.setOnClickListener(listener); button3.setOnClickListener(listener); button4.setOnClickListener(listener); button5.setOnClickListener(listener); button6.setOnClickListener(listener); } private View.OnClickListener listener =new View.OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub Button button =(Button)v; switch(button.getId()){ case R.id.button1: Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:15734449289")); startActivity(intent); break; case R.id.button2: Intent intent2=new Intent(); intent2.setAction(Intent.ACTION_SENDTO); intent2.setData(Uri.parse("smsto:15734449289")); intent2.putExtra("sms_body", "你好,加油"); startActivity(intent2);break; case R.id.button3: Uri uri=Uri.parse("http://www.baidu.com"); Intent intent3=new Intent(Intent.ACTION_VIEW,uri); startActivity(intent3);break; case R.id.button4: Uri uri2=Uri.parse("geo:38.899533,-77.036476"); Intent intent4=new Intent(Intent.ACTION_VIEW,uri2); startActivity(intent4);break; case R.id.button5: Toast.makeText(MainActivity.this, "666", Toast.LENGTH_LONG).show(); Uri uri3=Uri.parse("tel:15734449289"); Intent intent5=new Intent(Intent.ACTION_CALL,uri3); startActivity(intent5);break; /*case R.id.button6: Uri uri4 = Uri.parse("file:///sdcard/song.mp3"); Intent it = new Intent(Intent.ACTION_VIEW, uri4); it.setType("audio/mp3"); startActivity(it); break;*/ } } }; }
前5个功能都能去实现。第六个在想…..
<uses-permission android:name="android.permission.CALL_PHONE"/>//打电话加的功能 <uses-permission android:name="android.permission.SEND_SMS"/> //发短信加的功能
Intent学习博客推荐
http://www.cnblogs.com/engine1984/p/4146621.html
阅读全文
0 0
- Intent的几个基本事件
- Intent的基本用法
- FileStorge相关的几个intent
- 几个事件的顺序
- UIControl的几个事件
- JavaScript的几个事件
- Android Intent的基本搞法
- intent的一些基本用法
- 基本的几个排序
- 几个基本的算法
- 几个基本的概念
- Android Intent的几个主要用法
- Android Intent的几个主要用法
- Android之记录几个Uri的Intent.
- 几个实用性跟Intent有关的功能
- Intent.ACRION.view , Intent.Action.pick intent.action.get_content几个的理解
- 关于DataGird的几个事件
- 几个窗体事件的顺序
- Bellman-ford算法判断有无负环
- node 连接MongoDB
- 递归程序(未完待续)
- 专业安装全局的cnpm,查看node、npm、cnpm版本
- Java编码规范,让你的代码赏心悦目--类
- Intent的几个基本事件
- Java编码规范,让你的代码赏心悦目--迭进
- java web邮件收发组件
- HDU 6205 模拟题
- O
- java连接数据库的一些方法记载
- 异常、file类
- Lucene 6.0以上版本使用IKAnalyzer分词器
- js中数组和对象的复制