1. Black Friday Sale - 50% off

    B4A Standard for $29 instead of $59!
    Buy Now
    Dismiss Notice

Android Question how can show unread sms in box?

Discussion in 'Android Questions' started by khosrwb, Apr 28, 2015.

  1. khosrwb

    khosrwb Active Member Licensed User

    I want to show unread SMS in a box or listview.
    I know its big ask.
     
  2. eurojam

    eurojam Well-Known Member Licensed User

    you can try this code:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
        Dim cr As ContentResolver
        cr.Initialize(
    "")
        
    Dim u As Uri
        
    Dim pr() As String
        pr = 
    Array As String ( "_id""address""date""body" )
        u.Parse(
    "content://sms/inbox")
        
    Dim crsr As Cursor = cr.Query( u, pr , "read = 0"NullNull)
        
    Log("Rows " & crsr.RowCount)
        
    Log("Columns " & crsr.ColumnCount)
        
    For i=0 To crsr.RowCount-1
          crsr.Position = i
          
    Log(crsr.GetString("_id") & "-" & crsr.GetString("date"))
       
       
    Next
    End Sub
    this requires the READ_SMS permission: AddPermission(android.permission.READ_SMS) to the manifest editor
    uses the SQL-Lib and ContentResolver-Lib

    stefan
     
    Last edited: Apr 28, 2015
    khosrwb likes this.
  3. khosrwb

    khosrwb Active Member Licensed User

    hi
    I use them , but when I run app
    no action occored:(
    How should I use?
    If possible please use one label or other objects to show results.
     
  4. eurojam

    eurojam Well-Known Member Licensed User

    The example code I've posted does only write the results in the log. If you use the debug mode and set the log to filtered you will see what happens. Now you have to take my code snipplet and build your code around, for example fill a listview with it:
    Code:
    Sub Globals
        
    Dim ListView1 As ListView
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
        Dim cr As ContentResolver
        cr.Initialize(
    "")
        
    Dim u As Uri
        
    Dim pr() As String
        pr = 
    Array As String ( "_id""address""date""body" )
        u.Parse(
    "content://sms/inbox")
        
    Dim crsr As Cursor = cr.Query( u, pr , "read = 0"NullNull)
        
    Log("Rows " & crsr.RowCount)
        
    Log("Columns " & crsr.ColumnCount)
        ListView1.Initialize(
    "ListView1")
        
    For i=0 To crsr.RowCount-1
           crsr.Position = i
           ListView1.AddSingleLine(crsr.GetString(
    "_id") & "-" & crsr.GetString("date"))
         
    Next
        
    Activity.AddView(ListView1, 00100%x100%y)
    End Sub
    Sub ListView1_ItemClick (Position As Int, Value As Object)
      
    Activity.Title = Value
    End Sub
     
    mangojack and khosrwb like this.
  5. khosrwb

    khosrwb Active Member Licensed User

    very thanks


    I used this code to count sms.
    Code:
    Button5.Text=""&i

    But , when run app and resive a new sms
    Variable i is not change when a new sms (( when come on a new sms )).
    What can be done to solve this problem?

    excuse me for my bad english language
     
    Last edited: Apr 29, 2015
  6. eurojam

    eurojam Well-Known Member Licensed User

  7. khosrwb

    khosrwb Active Member Licensed User

    thanks stefan
    it's true
     
  8. khosrwb

    khosrwb Active Member Licensed User

    hi
    I need to id sms , for show spesial sms in label , but when I use from this code :


    Code:
    Sub Activity_Create(FirstTime As Boolean)
          ListView1.AddTwoLines(crsr.GetString(
    "_id") ,crsr.GetString("body"))
          mysms=crsr.getstring(
    "body")
          smsid=(crsr.getstring(
    "_id"))
    end sub

    Sub ListView1_ItemClick (Position As Int, Value As Object)
      label1.Text=mysms
    End Sub

    my app don't work truly , actually don't show sms truly:( (( my app show other sms ))
    like:
    I have 150 sms. but last id=161
    I don't know what to do:(
     
    Last edited: May 1, 2015
  9. Erel

    Erel Administrator Staff Member Licensed User

    Why don't you use SmsMessages from the Phone library?
     
  10. khosrwb

    khosrwb Active Member Licensed User

    how can I use them?
    I used them but I can't use very good from them:(
    I need to use under code from owne app

    Code:
    sms_idkey=Sms.Id
    threadid_dat=
    Sms.ThreadId
    datelog_dat=DateUtils.TicksToString(
    Sms.Date)
    readsms_dat=
    Sms.Read
    bodysms_dat=
    Sms.Body
    addresscp_dat=
    Sms.Address
    person_dat=
    Sms.PersonId
    smsType=
    Sms.Type
     
  11. eurojam

    eurojam Well-Known Member Licensed User

  12. khosrwb

    khosrwb Active Member Licensed User

    I can show sms but I will show sms by
    Code:
    sms.id
    I will use sms.id for show but I don't work with it ((work trully ))
    my app don't work truly , actually don't show sms truly:( (( my app show other sms ))
    like:
    I have 150 sms. but last id=161 ((sms.id=161)):confused::confused:
    I don't know what to do!?:(


    actually I will load Special sms on label by click on Special listview item and I will to show sms time resive (( i use under code: ))
    Code:
    smsTimeResive=DateUtils.TicksToString(Sms.Date)
     
    Last edited: May 1, 2015
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice