You don't need to use the telephone class, use a Broadcast reciever
to grab messages as thay come in, as such
public void onReceive(Context context, Intent intent)
{
// if the abort command is issued this will execute when the
next message is received.
// The message will not be processed and this instance will be
removed as a receiver.
if (intent.getAction().equals
(ACTION_RECIEVED))
{
System.out.println("getting messages.");
// retrieve the received sms messages form the intent.
Bundle bundle = intent.getExtras();
if ( bundle==null)
{
System.out.println("Message bundle is null!");
return;
}
else
{
// retrieve all incoming messages that haven't been
processed.
// typically will be only one message per receive event.
Object[] pdusObj = (Object[]) bundle.get("pdus");
if ( pdusObj==null )
{
System.out.println("Message pdu's are null!");
return;
}
SmsMessage[] messages = new SmsMessage[pdusObj.length];
System.out.println("retrieving: "+pdusObj.length+"
messages.");
for (int i = 0; i<pdusObj.length; i++)
{
// create the message from the pdu
messages[i] = SmsMessage.createFromPdu ((byte[])
pdusObj
[i]);
System.out.println("Message: "+i+" "+messages
[i].getMessageBody());
System.out.println("Message from: "+messages
[i].getOriginatingAddress());
}
}
}
}
Register your reciever as such:
IntentFilter filter = new IntentFilter
("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(new Reciever(), filter);
On Feb 10, 10:31 pm, David Hu <[email protected]> wrote:
> Hello, everyone
>
> I am using the Telephony class to get messages
> ( Telephony.Sms.Intents.getMessageFromIntent(Intent intent)). But I can't
> find the class Telephony from its package(android.provider), there is an
> error named "The import android.provider.Telephony cannot be resolved" when
> import android.provider.Telephony.Sms.Intents, the sdk version I'm using is
> android-sdk-windows-1.0_r2, how can I use this with the new implementation
> of Telephony?
>
> SmsMessage[] messages = Intents.getMessagesFromIntent(intent);
>
> I'll give my thanks in advance
>
> David
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---