我需要获取短信列表并像在股票应用程序或 Go 短信专业版中一样显示它们。我正在使用以下代码:
uriSms = Uri.parse("content://mms-sms/conversations");
Cursor cursor = getContentResolver().query(uriSms, new String[] {"*"}, null, null, "date DESC");
cursor.moveToFirst();
do{
try{
String address = cursor.getString(32);
if(address == null){
address = ""; //phone number
}else{
address = getContactName(address);
}
String body = cursor.getString(2);
System.out.println("======> Mobile number => "+address);
System.out.println("=====> SMS Text => "+body);
}catch (Exception e) {
e.printStackTrace();
}
}while(cursor.moveToNext());
它适用于我的 galaxy 选项卡 (android 2.2),但在我的 s3 (ICS) 应用程序启动时崩溃。我不想解析彩信,所以我尝试使用
uriSms = Uri.parse("content://sms/conversations");
但它在两种设备上都不起作用。我在谷歌上搜索了很多以找到解决方案,但一无所获。我只发现访问短信对话取决于 android 操作系统和设备。我的目的是制作支持每个 android 设备 2.2+ 的应用程序。在库存应用程序中,他们使用 Thread.CONTENT_URI 获取短信列表作为对话,例如。
Threads.CONTENT_URI.buildUpon().appendQueryParameter("simple", "true").build();
但是 Thread 类没有提供源代码,我在互联网上找不到它。 我该怎么做才能让我的应用程序像 Handcent Sms 或 GO sms pro 一样在每个 android 设备 (2.2+) 上运行。
最佳答案
您的代码崩溃是因为您假设查询表包含一个名为 address 的列,其中并非所有 android 版本都在对话中存储地址。要检查表的结构,您可以通过以下代码显示其列名和内容:
ArrayList<String> conversation = new ArrayList<>();
Uri uri = Uri.parse( "content://sms/conversations/" );
Cursor cursor = getContentResolver().query( uri, null, null ,null, null );
startManagingCursor( cursor );
if( cursor.getCount() > 0 ) {
String count = Integer.toString( cursor.getCount() );
while( cursor.moveToNext() ) {
String result = "";
for( int i = 0; i < cursor.getColumnCount(); i++ ) {
result = result + "\nindex " + i + "\n column is "
+ cursor.getColumnName( i ) + "\nvalue is " + cursor.getString( i );
}
result = result + "\n new conversation";
conversation.add( result );
}
}
cursor.close();
一种可能的解决方法是使用 thread_id 作为参数来搜索地址,如下所示:
ArrayList<String> conversation = new ArrayList<>();
// We may use sms/sent or sms/inbox
Uri uri = Uri.parse( "content://sms" );
Cursor cursor = getContentResolver().query( uri, null, "thread_id" + " = " + threadId ,null, null );
startManagingCursor( cursor );
if( cursor.getCount() > 0 ) {
String count = Integer.toString( cursor.getCount() );
while( cursor.moveToNext() ){
String result = "";
for( int i = 0; i < cursor.getColumnCount(); i++ ) {
result = result + "\nindex " + i + "\n column is "
+ cursor.getColumnName( i ) + "\nvalue is " + cursor.getString( i );
}
result = result + "\n new conversation";
conversation.add( result );
}
}
cursor.close();
关于android - 如何在每个 Android 设备 2.2+ 中获取短信列表作为对话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13210420/
出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
exe应该在我打开页面时运行。异步进程需要运行。有什么方法可以在ruby中使用两个参数异步运行exe吗?我已经尝试过ruby命令-system()、exec()但它正在等待过程完成。我需要用参数启动exe,无需等待进程完成是否有任何rubygems会支持我的问题? 最佳答案 您可以使用Process.spawn和Process.wait2:pid=Process.spawn'your.exe','--option'#Later...pid,status=Process.wait2pid您的程序将作为解释器的子进程执行。除
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
鉴于我有以下迁移:Sequel.migrationdoupdoalter_table:usersdoadd_column:is_admin,:default=>falseend#SequelrunsaDESCRIBEtablestatement,whenthemodelisloaded.#Atthispoint,itdoesnotknowthatusershaveais_adminflag.#Soitfails.@user=User.find(:email=>"admin@fancy-startup.example")@user.is_admin=true@user.save!ende
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
我正在为一个项目制作一个简单的shell,我希望像在Bash中一样解析参数字符串。foobar"helloworld"fooz应该变成:["foo","bar","helloworld","fooz"]等等。到目前为止,我一直在使用CSV::parse_line,将列分隔符设置为""和.compact输出。问题是我现在必须选择是要支持单引号还是双引号。CSV不支持超过一个分隔符。Python有一个名为shlex的模块:>>>shlex.split("Test'helloworld'foo")['Test','helloworld','foo']>>>shlex.split('Test"
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121