Xamarin.Android之转换,呼叫,查看历史纪录
Xamarin.Android之转换,呼叫,查看历史纪录
功能:能将输入的字母转换成相应的数字。并且能呼叫出去。能查看呼叫的历史纪录。
界面代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="0712-XAMARIN"
android:id="@+id/et"
/> <Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="转换"
android:id="@+id/btnTran"
/> <Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="呼叫"
android:id="@+id/btnCall"
/> <Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="历史纪录"
android:id="@+id/btnCallHistory"
/> </LinearLayout>
主Activity代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget; namespace App3
{
[Activity(Label = "CallActivity", MainLauncher = true, Icon = "@drawable/icon2")]
public class CallActivity : Activity
{
//定义手机集合。
private static readonly List<string> PhoneNumbers = new List<string>();
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Call);
EditText et = FindViewById<EditText>(Resource.Id.et);
Button btnTran = FindViewById<Button>(Resource.Id.btnTran);
Button btnCall = FindViewById<Button>(Resource.Id.btnCall);
btnCall.Enabled = false;
Button btnCallHistory = FindViewById<Button>(Resource.Id.btnCallHistory);
btnCallHistory.Enabled = false;
string translatedNumber = string.Empty; btnTran.Click += (sender, e) =>
{
translatedNumber = PhoneTranslator.ToNumber(et.Text);
//将转换的手机号加入到手机集合中。
PhoneNumbers.Add(translatedNumber);
btnCallHistory.Enabled = true;
if (String.IsNullOrWhiteSpace(translatedNumber))
{
btnCall.Text = "呼叫";
btnCall.Enabled = false;
}
else
{
btnCall.Text = "呼叫" + translatedNumber;
btnCall.Enabled = true;
}
}; btnCall.Click += (sender, e) =>
{
//对话框
var callDialog = new AlertDialog.Builder(this);
callDialog.SetMessage("呼叫" + translatedNumber + "?");
//拨打按钮
callDialog.SetNeutralButton("呼叫", delegate
{
//使用意图拨打电话
var callIntent = new Intent(Intent.ActionCall);
//将需要拨打的电话设置为意图的参数.注意写法
callIntent.SetData(Android.Net.Uri.Parse("tel:" + translatedNumber));
StartActivity(callIntent);
});
callDialog.SetNegativeButton("取消", delegate { });
callDialog.Show();
}; btnCallHistory.Click += (sender, e) =>
{
//用意图打开历史纪录的活动
Android.Content.Intent it = new Intent(this, typeof(CallHistoryActiviry));
it.PutStringArrayListExtra("phoneNumbers", PhoneNumbers);
StartActivity(it);
}; }
}
}
通话纪录的Activity代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget; namespace App3
{
[Activity(Label = "CallHistoryActiviry")]
public class CallHistoryActiviry : ListActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var phoneNumbers = Intent.Extras.GetStringArrayList("phoneNumbers") ?? new string[];
//只有当此Activity继承于ListActivity时,整个视图才是列表,才可以这么写。
this.ListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleExpandableListItem1, phoneNumbers);
}
}
}
Xamarin.Android之转换,呼叫,查看历史纪录的更多相关文章
- Xamarin.Android开发
使用 Visual Studio 生成第一个 Xamarin.Android 应用程序,并进一步了解使用 Xamarin 进行 Android 应用程序开发的基础知识.在此过程中,会介绍生成和部署 X ...
- Xamarin. Android实现下拉刷新功能
PS:发现文章被其他网站或者博客抓取后发表为原创了,给图片加了个水印 下拉刷新功能在安卓和iOS中非常常见,一般实现这样的功能都是直接使用第三方的库,网上能找到很多这样的开源库.然而在Xamarin. ...
- Xamarin.Android开发实践(十四)
Xamarin.Android之ListView和Adapter 一.前言 如今不管任何应用都能够看到列表的存在,而本章我们将学习如何使用Xamarin去实现它,以及如何使用适配器和自定义适配器(本文 ...
- Xamarin.Android Binding篇
前言 趁着失业了,闲着没事儿学习了下Xamarin.Android binding,在以往的开发中,我相信很多人都遇到过binding的坑,也不例外, 我也踩了很多雷,好在认识了个大佬,指导了很多 ...
- xamarin.android 绑定百度地图SDK遇到的问题
在 xamarin.android 绑定项目中,绑定 百度地图的LBS地图SDK,参考 https://developer.xamarin.com/guides/android/advanced_to ...
- Xamarin android如何反编译apk文件
Xamarin android 如何反编译 apk文件 这里推荐一款XamarinAndroid开发的小游戏,撸棍英雄,游戏很简单,的确的是有点大.等一下我们来翻翻译这个Xamarin Android ...
- Xamarin.Android之ListView和Adapter
一.前言 如今不管任何应用都能够看到列表的存在,而本章我们将学习如何使用Xamarin去实现它,以及如何使用适配器和自定义适配器(本文中的适配器的主要内容就是将原始的数据转换成了能够供列表控件显示的项 ...
- APP并非一个人在战斗,还有API—Xamarin.Android回忆录
前言 一般来说,一个客户端APP并非独立存在的,很多时候需要与服务器交互.大体可分为两方面的数据,常规字符串数据和文件数据,因为这两种数据很可能传输方式不一样,比如字符串之类的数据,使用HTTP协议, ...
- Xamarin.Android之SQLiteOpenHelper
一.前言 在手机中进行网络连接不仅是耗时也是耗电的,而耗电却是致命的.所以我们就需要数据库帮助我们存储离线数据,以便在用户未使用网络的情况下也可以能够使用应用的部分功能,而在需要网络连接的功能上采用提 ...
随机推荐
- C++ 必知必会: 条款1: 数据抽象
数据抽象, 具有C语言经理的我, 原先是将其看做是一个数据的集合, 把自己常用的数据通过某种方式总结,集合起来, 使用的时候能够更加方便------其实这个还是结构体思想的延续,结构体内部包含了若干的 ...
- 设计模式-适配器模式(Adapter)
简介: 适配器模式在我看来是最无聊的一种模式,因为他根本不是一种新的创意模式,而是一种不得已而为之的模式.就算不学适配器模式,在具体应用场景中也会自然而然的想到这种解决方案. 张三在英国留学时买了个笔 ...
- RocketMQ学习记录
RocketMQ是一款分布式.队列模型的消息中间件,具有以下特点: 1.能够保证严格的消息顺序 2.提供丰富的消息拉取模式 3.高效的订阅者水平扩展能力 4.实时的消息订阅机制 5.亿级消息堆积能力 ...
- ThinkPHP整合支付宝即时到账接口调用
首先是在支付宝的蚂蚁金服开放平台下载PHP的demo: https://doc.open.alipay.com/doc2/detail?treeId=62&articleId=103566&a ...
- 会写网页 就会写手机APP -- Hybrid Mobile Apps for ASP.NET Developers
您好,这篇文章是我的BLOG发出,原始出处在此: 会写网页 就会写手机APP -- Hybrid Mobile Apps for ASP.NET Developers http://www.dotbl ...
- 大话RAC介质恢复---联机日志损坏
对联机日志的损坏要根据日志状态进行分析,联机日志一般会有Current.Active和Inactive三种状态.Inactive状态不会造成数据丢失.而Active和Current状态的日志一般会造成 ...
- MySQL 的数值数据类型
MySQL 的数值数据类型可以大致划分为两个类别,一个是整数,另一个是浮点数或小数.许多不同的子类型对这些类别中的每一个都是可用的,每个子类型支持不同大小的数据,并且 MySQL 允许我们指定数值字段 ...
- DIV指令一般用法
本文最初发表于2015-8-14,是由别的地方迁移过来的 (本文所讲为无符号运算) DIV指令是8086汇编中的除法运算指令,它的结果不是浮点数,而是两个整数:商和余数. 我们来看王爽老师是怎么讲的: ...
- 微软CRM解决医药企业串货之痛
没有准确.及时的流向数据统计和分析,医药企业营销部门就无法有效管理串货泛滥问题,串货会造成渠道无利可赚,挫伤渠道的积极性,产品无人愿意卖,最终伤害的还是医药企业. 医药企业营销发展的不同阶段对串货的态 ...
- 基于AppCan MAS系统,如何轻松实现移动应用数据服务?
完成一个移动应用开发,前端提供页面展示,当它要与一些业务系统进行交互,又该如何实现呢?2016AppCan移动开发者大会上,AppCan前端开发经理杨庆,分享了AppCan轻松实现移动应用数据服务的方 ...