Android开发之短信
短信主要界面:会话列表,会话详情,新建短信。
联系人主要界面:联系人列表,编辑联系人。
创建首页。首页由TabActivity表现。
在Android4.1中,TabActivity处于保护状态。
The type TabActivity is deprecated
没关系,继续使用。
[Accessibility] Missing contentDescription attribute on image
将会话分为两种:单一收件人会话。多个收件人会话。
在XXXAdapter.getView中,使用converView.setTag(Object)和getTag()。
得到会话时间。昨天,今天,等等。
创建一个Application子类TxrjApplication
android.app.Application
Base class for those who need to maintain global application state. You can provide your own implementation by specifying its name in your AndroidManifest.xml's <application> tag, which will cause that class to be instantiated for you when the process for your application/package is created.
There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a android.content.Context which internally uses Context.getApplicationContext() when first constructing the singleton.
要点:用来维护全局应用状态。在AndroidManifest.xml文件中<application>标签中指定名字,然后你可以提供Application的实现。当应用包的进程创建时,Application会被实例化。
<uses-permission> tag appears after <application> tag
<uses-permission>标签必须放在<application>之前。
使用AsyncTask来获取会话列表。
去掉Activity的标题栏两种办法
1.在代码中设置
requestWindowFeature(Window.FEATURE_NO_TITLE);
2.在AndroidManifest.xml文件中<application>标签中设置
android:theme="@android:style/Theme.NoTitleBar"
参考链接:
添加一条草稿时出现空指针异常
07-05 14:30:55.966: E/AndroidRuntime(11857): FATAL EXCEPTION: main
07-05 14:30:55.966: E/AndroidRuntime(11857): java.lang.NullPointerException
07-05 14:30:55.966: E/AndroidRuntime(11857): at com.txrj.sms.common.TxrjUtils.getString(TxrjUtils.java:20)
07-05 14:30:55.966: E/AndroidRuntime(11857): at com.txrj.sms.adapter.ConversationListAdapter.getView(ConversationListAdapter.java:102)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.AbsListView.obtainView(AbsListView.java:2485)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.ListView.makeAndAddView(ListView.java:1780)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.ListView.fillDown(ListView.java:678)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.ListView.fillFromTop(ListView.java:738)
07-05 14:30:55.966: E/AndroidRuntime(11857): at android.widget.ListView.layoutChildren(ListView.java:1631)
已经fix:
holder.draft.setText("["+TxrjUtils.getString(mContext, R.string.sms_draft)+"]");
此语句中第一个实参mContext为空,没有在构造方法中赋值导致。
会话列表加载有点点慢!
ListView的Item点击事件实现步骤:
1. ListView.setOnItemClickListener
2. implements AdapterView.OnItemClickListenr
3. (override) onItemClick(AdapterView parent, View view, int position, long id)
点击APP图标显示会话列表时出现异常
07-06 10:40:46.015: E/AndroidRuntime(10057): FATAL EXCEPTION: main
07-06 10:40:46.015: E/AndroidRuntime(10057): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.txrj.sms/com.txrj.sms.activity.ConversationListActivity}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.os.Looper.loop(Looper.java:137)
07-06 10:40:46.015: E/AndroidRuntime(10057): at android.app.ActivityThread.main(ActivityThread.java:4517)
mCreateMsgBtn = (Button) findViewById(R.id.create_message);
将(Button)改成(ImageButton)
点击会话列表中的一个item出现异常1
07-06 10:47:31.150: E/AndroidRuntime(10967): FATAL EXCEPTION: main
07-06 10:47:31.150: E/AndroidRuntime(10967): android.content.ActivityNotFoundException: No Activity found to handle Intent { (has extras) }
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1536)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1388)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.app.Activity.startActivityForResult(Activity.java:3195)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.app.Activity.startActivity(Activity.java:3302)
07-06 10:47:31.150: E/AndroidRuntime(10967): at com.txrj.sms.activity.ConversationListActivity.onItemClick(ConversationListActivity.java:67)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.widget.AbsListView.performItemClick(AbsListView.java:1427)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3057)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.widget.AbsListView$1.run(AbsListView.java:3970)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.os.Handler.handleCallback(Handler.java:605)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 10:47:31.150: E/AndroidRuntime(10967): at android.os.Looper.loop(Looper.java:137)
添加语句:it.setClass(mContext, MessageListActivity.class);
点击会话列表中的一个Item出现异常2
07-06 10:51:37.861: E/AndroidRuntime(11331): FATAL EXCEPTION: main
07-06 10:51:37.861: E/AndroidRuntime(11331): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.txrj.sms/com.txrj.sms.activity.MessageListActivity}: android.view.InflateException: Binary XML file line #70: Error inflating class EditView
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 10:51:37.861: E/AndroidRuntime(11331): at android.os.Looper.loop(Looper.java:137)
标签名字出错了,将(EditView)改成(EditText)。
进入MessageListActivity中出现异常1
07-06 10:57:03.539: E/AndroidRuntime(11815): FATAL EXCEPTION: main
07-06 10:57:03.539: E/AndroidRuntime(11815): java.lang.NullPointerException
07-06 10:57:03.539: E/AndroidRuntime(11815): at com.txrj.sms.activity.MessageListActivity$LoadMessagesTask.onPostExecute(MessageListActivity.java:78)
07-06 10:57:03.539: E/AndroidRuntime(11815): at com.txrj.sms.activity.MessageListActivity$LoadMessagesTask.onPostExecute(MessageListActivity.java:1)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.AsyncTask.finish(AsyncTask.java:602)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.AsyncTask.access$600(AsyncTask.java:156)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.Handler.dispatchMessage(Handler.java:99)
07-06 10:57:03.539: E/AndroidRuntime(11815): at android.os.Looper.loop(Looper.java:137)
mListView = (ListView) findViewById(R.id.threads_list);
将(threads_list)改成(message_list)
进入MessageListActivity中出现异常2
07-06 11:11:20.795: E/AndroidRuntime(12676): FATAL EXCEPTION: main
07-06 11:11:20.795: E/AndroidRuntime(12676): android.view.InflateException: Binary XML file line #42: Error inflating class tyu.common.ui.component.TyuTextView
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-06 11:11:20.795: E/AndroidRuntime(12676): at com.txrj.sms.adapter.MessageListAdapter.getView(MessageListAdapter.java:90)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.widget.AbsListView.obtainView(AbsListView.java:2485)
07-06 11:11:20.795: E/AndroidRuntime(12676): at android.widget.ListView.makeAndAddView(ListView.java:1780)
将(tyu.common.ui.component.TyuTextView)改成(TextView)
在MessageListActivity中上下滑动时出现异常1
07-06 11:14:27.728: E/AndroidRuntime(13371): FATAL EXCEPTION: main
07-06 11:14:27.728: E/AndroidRuntime(13371): java.lang.NullPointerException
07-06 11:14:27.728: E/AndroidRuntime(13371): at com.txrj.sms.adapter.MessageListAdapter.getView(MessageListAdapter.java:99)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.AbsListView.obtainView(AbsListView.java:2464)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.ListView.makeAndAddView(ListView.java:1780)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.ListView.fillUp(ListView.java:711)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.ListView.fillGap(ListView.java:651)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5877)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:5018)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.os.Handler.handleCallback(Handler.java:605)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 11:14:27.728: E/AndroidRuntime(13371): at android.os.Looper.loop(Looper.java:137)
添加语句:convertView.setTag(holder);
在MessageListActivity中的信息列表ListView中,send的信息变成receiver的信息了。
删除掉TrxjMessage类中的status字段。
使用type字段即可,type说明如下:
public interface TextBasedSmsColumns {
/**
* The type of the message
* <P>Type: INTEGER</P>
*/
public static final String TYPE = "type";
public static final int MESSAGE_TYPE_ALL = 0;
public static final int MESSAGE_TYPE_INBOX = 1;
public static final int MESSAGE_TYPE_SENT = 2;
public static final int MESSAGE_TYPE_DRAFT = 3;
public static final int MESSAGE_TYPE_OUTBOX = 4;
public static final int MESSAGE_TYPE_FAILED = 5; // for failed outgoing messages
public static final int MESSAGE_TYPE_QUEUED = 6; // for messages to send later
在MessageListActivity中上下滑动时出现异常2
07-06 11:32:03.428: E/AndroidRuntime(14253): FATAL EXCEPTION: main
07-06 11:32:03.428: E/AndroidRuntime(14253): java.lang.NullPointerException
07-06 11:32:03.428: E/AndroidRuntime(14253): at com.txrj.sms.adapter.MessageListAdapter.getView(MessageListAdapter.java:109)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.AbsListView.obtainView(AbsListView.java:2464)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.ListView.makeAndAddView(ListView.java:1780)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.ListView.fillUp(ListView.java:711)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.ListView.fillGap(ListView.java:651)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5877)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:5018)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.os.Handler.handleCallback(Handler.java:605)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 11:32:03.428: E/AndroidRuntime(14253): at android.os.Looper.loop(Looper.java:137)
使用if(type == Telephony.Sms.MESSAGE_TYPE_INBOX){…} else {…}
去掉TrxjMessage.SEND, TrxjMessage.RECEIVE
使用convertView.setTag(viewHolder), convertView.getTag(); 需要注意 ListView中的每个item都有相同的结构和元素。
目前,receive的信息没有status和progressBar,send的信息有。
如果以receiver的layout文件构建convertView,当遇到send的view时,也没有status和progressBar。
就会出现空指针异常。
07-06 12:02:53.102: E/AndroidRuntime(18854): FATAL EXCEPTION: main
07-06 12:02:53.102: E/AndroidRuntime(18854): java.lang.NullPointerException
07-06 12:02:53.102: E/AndroidRuntime(18854): at com.txrj.sms.adapter.MessageListAdapter.getView(MessageListAdapter.java:112)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.AbsListView.obtainView(AbsListView.java:2464)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.ListView.makeAndAddView(ListView.java:1780)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.ListView.fillUp(ListView.java:711)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.ListView.fillGap(ListView.java:651)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5877)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:5018)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.os.Handler.handleCallback(Handler.java:605)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 12:02:53.102: E/AndroidRuntime(18854): at android.os.Looper.loop(Looper.java:137)
holder.status = (TextView) convertView.findViewById(R.id.status);
将(R.id.send_status)改成(R.id.status)
Android开发之短信的更多相关文章
- Android开发之短信验证码示例
在说Android中的短信验证码这个知识点前,我们首先来了解下聚合数据 聚合数据介绍 聚合数据是一家国内最大的基础数据API提供商,专业从事互联网数据服务.免费提供从天气查询.空气质量.地图坐标到金融 ...
- Android开发遇到短信备份失败
今天做了一个有关ContentProvider的短信备份的小案例,遇到短信备份失败,费了一番周折后终于找到了问题所在 该案例是将短信写到一个xml文件然后保存在手机存储中实现短信的备份功能,关键实现代 ...
- Android通讯:短信
Android通讯之短信功能实现: 使用android.telephony.SmsManager对象,可以发送短信和彩信.// 构造回调函数,短信发送结束后,会发出对应的Intent请求Intent ...
- android自动获取短信验证码
前言:android应用的自动化测试必然会涉及到注册登录功能,而许多的注册登录或修改密码功能常常需要输入短信验证码,因此有必要能够自动获得下发的短信验证码.主要就是实时获取短信信息.android上获 ...
- Android 趣味应用—— 短信编辑器
修改短信数据库,从而生成任意手机号发送的短信. AndroidManifest.xml <?xml version="1.0" encoding="utf-8&qu ...
- android之发送短信程序
首先改写activity_main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/re ...
- android自动填写短信验证码
广播类 package com.examp.azuoyoutong.listner; import java.util.regex.Matcher;import java.util.regex.Pat ...
- Android自动读取短信验证码
Android自动读取短信验证码 extends:http://www.cnblogs.com/jiayaguang/p/4366384.html,http://blog.csdn.net/yung ...
- android 监听短信数据库,制作短信控制工具,控制别人的手机!!(一)
序言:本程序示例本着简洁易懂的目的,只做了简单的功能实现,需要用户启动应用,收到短信才有效果.作者将会在后面的(二)篇中加入服务后台运行.自动启动功能,实现一个真正的短信控制工具.本文的目的很简单,让 ...
随机推荐
- Unity ScriptObject创建Asset文件
创建ScriptObject可以创建带序列化的资源,只保存数据不用绑定在游戏对象上.创建出来的本子资源可以通过资源加载到游戏里使用.这里介绍一下使用Resources加载. 创建好的asset文件也可 ...
- 也谈时间管理和GTD
也谈时间管理和GTD 时间管理 随着事情越来约多发现时间越来越不够用了,但是其实每天时间都是恒定的,并不增也不减,所以感觉时间不够用了总归只是个人主观感觉. 对我个人帮助比较大的是三本书<番茄时 ...
- WebDriver工作原理
http://www.cnblogs.com/timsheng/archive/2012/06/12/2546957.html 通过研究selenium-webdriver的源码,笔者发现其实webd ...
- C++虚函数、虚继承
http://blog.csdn.net/hackbuteer1/article/details/7883531 转载请标明出处,原文地址:http://blog.csdn.net/hackbutee ...
- UVA 10972 RevolC FaeLoN(边-双连通+缩点)
很好的一道图论题,整整撸了一上午... 题意是给定一个无向图,要求将所有边变为有向边,求最少加入多少条有向边,使得该图强连通?这里先假设一个问题:给定一个无向子图,该子图具有怎样的性质才能使得将其无向 ...
- Use a TL431 shunt regulator to limit high ac input voltage
Most isolated, offline SMPSs (switched-mode power supplies), including flyback, forward, and resonan ...
- Fixed DC-DC Regulator Output Uses A Digitally Controlled Potentiometer
http://electronicdesign.com/print/passives/fixed-dc-dc-regulator-output-uses-digitally-controlled-po ...
- Spring依赖检查
在Spring中,可以使用依赖检查功能,以确保所要求的属性可设置或者注入. 依赖检查模式 4个依赖检查支持的模式: none – 没有依赖检查,这是默认的模式. simple – 如果基本类型(int ...
- Ubuntu下gcc多版本共存和版本切换
https://my.oschina.net/u/2306127/blog/538139 摘要: Ubuntu系统使用的gcc版本随着发布版本的不同而不同,在编译android系统时不同的版本推荐用不 ...
- Spark调研笔记第4篇 - PySpark Internals
事实上.有两个名为PySpark的概念.一个是指Sparkclient内置的pyspark脚本.而还有一个是指Spark Python API中的名为pyspark的package. 本文仅仅对第1个 ...