Tutorial: list received smss

donv edited this page Mar 24, 2013 · 6 revisions

Goal

List stored SMS messages.

Prerequisites

This tutorial has been tested with the following setups

Platform JDK ant Ruby ruboto RubotoCore Device API level Tester
OS X 10.8.3 1.7.0_15 1.8.4 MRI 2.0.0 0.11.0.dev 0.5.3 Samsung Galaxy S3 android-15 donv

Create the app, install, and run it

Connect your device.

ruboto gen app --package org.ruboto.example.sms_list
cd sms_list
rake update_scripts:restart

You should see the standard "What hath Matz wrought?" screen.

A fresh app

Change the layout

Edit src/sms_list.rb to this:

require 'ruboto/widget'

ruboto_import_widgets :LinearLayout, :ListView

class SmsListActivity
  def onCreate(bundle)
    super
    set_title 'Ruboto SMS List'

    self.content_view =
        linear_layout :orientation => :vertical do
          @list_view = list_view :list => []
        end
  end

  def onResume
    super
    cursor = content_resolver.query(android.net.Uri.parse('content://sms/inbox'), nil, nil, nil, nil)
    if cursor.moveToFirst
      messages = []
      begin
        messages << (0...cursor.column_count).map { |i| "#{cursor.getColumnName(i)}:#{cursor.getString(i)}" }.join(', ')
      end while cursor.moveToNext
      cursor.close
      @list_view.adapter.add_all messages
    end
  end
end

Add SMS reading permission

Add this line to your AndroidManifest.xml just below the uses-sdk tag:

  <uses-permission android:name='android.permission.READ_SMS'/>

Install the app

rake install start
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.