Go Back   Android Forums > Android Development > Application Development
Application Development Dev Lounge for the Coder Folks
Gamers - Check out our new sister sites!
Nintendo Wii U!    |    OUYA - $99 Android System!

test: Reply
 
LinkBack Thread Tools
Old July 31st, 2011, 11:54 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2011
Posts: 4
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Alert problem in SMSreceiver.class

Hi
I am new here. I are making a app, where it must show a alert on sms message.

But this line do not work:
AlertDialog.Builder(this).setTitle("asd").setMessa ge(str).setNegativeButton("Annuller", null).setPositiveButton("Bekræft", null).show();

I am not sure if it is because of this class run i background or what?

This is the class:
Code:
package net.sms;
 
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.widget.Toast;
 
public class SmsReceiver extends BroadcastReceiver
{
	
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        //---get the SMS message passed in---
        Bundle bundle = intent.getExtras();        
        SmsMessage[] msgs = null;
        String str = "";            
        if (bundle != null)
        {
            //---retrieve the SMS message received---
            Object[] pdus = (Object[]) bundle.get("pdus");
            msgs = new SmsMessage[pdus.length];            
            for (int i=0; i<msgs.length; i++){
                msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                
                str += "SMS from " + msgs[i].getOriginatingAddress();                     
                str += " :";
                str += msgs[i].getMessageBody().toString();
                str += "\n";        
            }
            AlertDialog.Builder alt_bld = new AlertDialog.Builder(context);
            alt_bld.setTitle("aaa");
            alt_bld.show();
            //new AlertDialog.Builder(this).setTitle("asd").setMessage(str).setNegativeButton("Annuller", null).setPositiveButton("Bekræft", null).show();
            //---display the new SMS message---
            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
        }                         
    }
}

boje is offline  
Reply With Quote
Sponsors
Reply
Tags
alert dialog box, sms alert, sms receive


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:57 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.