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 监听短信数据库,制作短信控制工具,控制别人的手机!!(一)
序言:本程序示例本着简洁易懂的目的,只做了简单的功能实现,需要用户启动应用,收到短信才有效果.作者将会在后面的(二)篇中加入服务后台运行.自动启动功能,实现一个真正的短信控制工具.本文的目的很简单,让 ...
随机推荐
- HDU 5297 Y sequence 容斥 迭代
Y sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5297 Description Yellowstar likes integer ...
- java类中元素初始化顺序详解
父类静态变量父类静态块子类静态变量子类静态块父类普通变量父类普通块父类构造方法子类普通变量子类普通块子类构造方法
- PYPY_GC
Author:Jin Date: 2014-7-8 http://doc.pypy.org/en/latest/windows.html http://www.pypy.org/download.ht ...
- HDU 4585 Shaolin(水题,STL)
Shaolin Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- SMT Surface Mount Technology footprint references
http://en.wikipedia.org/wiki/Surface-mount_technology Surface-mount technology (SMT) is a method for ...
- [转].net reactor 学习系列(二)---.net reactor界面各功能说明
安装了.net reactor之后,可以在安装目录下找到帮助文档REACTOR_HELP.chm,目前没有中文版本,里面详细介绍了.net reactor的各功能及使用场景.本系列文章是基于此帮助文档 ...
- java string(2)
1. indexOf()函数是一个执行速度非常快的函数,可以用其与subString()实现高效的字符串分割,比内置的要高效. 2. charAt()方法也是高效率的函数,可以用其实现高效的start ...
- python笔记19-获取当前运行函数名称和类方法名称
前言 写完代码之后,一般为了方便查看日志,可以在日志输出中加入当前运行的函数名称或类和方法名称,以便于代码报错的时候能快速找到报错的是哪个函数或方法. 那么如何获取当前运行函数(或方法)的名称呢? 获 ...
- iOS开发之UITextField 左侧设置小图标 leftview
设置用户登录的时候,这个是避免不了,实现方法很多,我个人主张,系统有提供就使用系统,一来方便,二来运行效率高 Paste_Image.png 实现代码如下: pwdTextField.placehol ...
- Andorid之Annotation框架初使用(三)
线程使用: @Background这个是使用了cached thread pool executor , 阻止开启过多的线程 可以为@Background指定一个id,用于随时终止线程的操作(Back ...