android的常用方法,后续会一直增加
来源:互联网 发布:淘宝店家身份查询 编辑:程序博客网 时间:2024/05/14 23:20
简单的xml布局文件:
<RelativeLayout 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" tools:context=".MainActivity"> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="打开网页" android:id="@+id/onClickWeb" android:onClick="onClickWeb" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="打开拨号面板" android:id="@+id/onClickCallPhone" android:onClick="onClickCallPhone" android:layout_below="@+id/onClickWeb" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="拨打电话" android:id="@+id/callPhone" android:onClick="callPhone" android:layout_below="@+id/onClickCallPhone"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="打开发短信面板" android:id="@+id/onClickSendMessage" android:onClick="onClickSendMessage" android:layout_below="@+id/callPhone"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="发短信" android:id="@+id/onClickMessage" android:onClick="onClickMessage" android:layout_below="@+id/onClickSendMessage"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="播放多媒体" android:id="@+id/media" android:onClick="media" android:layout_below="@+id/onClickMessage"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="卸载程序" android:id="@+id/uninstall" android:onClick="uninstall" android:layout_below="@+id/media"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="安装程序" android:id="@+id/install" android:onClick="install" android:layout_below="@+id/uninstall"/></RelativeLayout>
相应的实现方法:
package com.example.zhushuyong.myintent;import android.content.Intent;import android.net.Uri;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import java.io.File;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } /** * 打开网页 * @param v */ public void onClickWeb(View v){ Uri data=Uri.parse("http://www.jeecms.com"); String action= Intent.ACTION_VIEW; Intent intent=new Intent(action,data); startActivity(intent); } /** * 打开拨号面板 * @param v */ public void onClickCallPhone(View v){ Uri data=Uri.parse("tel:123456789"); String action=Intent.ACTION_DIAL; Intent intent=new Intent(action,data); startActivity(intent); } /** * 拨打电话 * @param v */ public void callPhone(View v){ Uri data=Uri.parse("tel:123456789"); String action=Intent.ACTION_CALL; Intent intent=new Intent(action,data); startActivity(intent); } /** * 发送短信面板 * @param v */ public void onClickSendMessage(View v){ Intent intent=new Intent(); String action=Intent.ACTION_VIEW; intent.setAction(action); intent.putExtra("sms_body", "你今天吃了吗"); intent.setType("vnd.android-dir/mms-sms"); startActivity(intent); } /** * 发送短信 * @param v */ public void onClickMessage(View v){ Uri data=Uri.parse("smsto:123456789"); String action=Intent.ACTION_SENDTO; Intent intent=new Intent(action,data); intent.putExtra("sms_body", "一起吃个饭呗"); startActivity(intent); } /** * 播放多媒体 * @param v */ public void media(View v){ Uri data=Uri.parse("file:///sdcard/Music/Wiz Khalifa;Charlie Puth-See You Again.mp3"); String action=Intent.ACTION_VIEW; Intent intent=new Intent(); intent.setAction(action); intent.setDataAndType(data, "audio/mp3"); startActivity(intent); } /** * 卸载程序 * @param v */ public void uninstall(View v){ Uri data=Uri.parse("package:包名"); String action=Intent.ACTION_DELETE; Intent intent=new Intent(action,data); startActivity(intent); } /** * 安装程序 * @param v */ public void install(View v){ Uri data=Uri.fromFile(new File("sd卡路径")); String action=Intent.ACTION_VIEW; Intent intent=new Intent(); intent.setAction(action); intent.setDataAndType(data,"application/vnd.android.package-archive"); startActivity(intent); }}
布局图片
0 0
- android的常用方法,后续会一直增加
- 一直想写个js模板,现在终于写了个简单的版本,后续会增加更多功能(依赖jquery)
- 常用eclipse快捷键总结(后续会用增加)
- 一些不为人知的php试题(暂时就总结这些!后续会一直增加 大家觉得不全的请评论或者留言)
- 学习地址【后续会一直添加】
- gwt项目开发的经验集----会一直增加
- 常用小方法(后续)
- Django入门:使用技巧【后续会一直添加】
- Java 学习视频集 - 会一直增加
- fwrite为什么会导致内存一直增加。。。
- 常用的取数表(一直会追加和更新)
- javascript常用代码(会一直添加)
- android开发关于打包一个总结(后续一直更新)
- 【Android 应用开发】对Android体系结构的理解--后续会补充
- 继文章‘’ 自己动手写一个轻量级的Android网络请求框架‘’后续------增加缓存功能
- 调用 XmlSerializer.Deserialize 注意:会一直增加程序集。
- Android 增加包的方法
- Android 增加包的方法
- OpenStack 学习记录
- 送给以后的自己…
- 设置Swing 容器居中显示
- kali信息搜集工具之dnsenum
- 面向对象编程2
- android的常用方法,后续会一直增加
- ”时光已逝,涛声依旧“
- Cocos2dx 中常用的基本Action类(动作类)
- PHP面向对象(OOP)第二天
- java 中的 传值 与 传址
- 一个根据关键字(如qq号码)来过滤序列化网络包的重要命令------awk和sed同时登场
- Validate Binary Search Tree
- 我想我迷上了Material Design
- 第17章 错误处理与调试