Recognize/React on incoming SMS

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Re: Recognize/React on incoming SMS

Postby DMacATTACK » Tue Jan 10, 2012 1:21 am

Off hand I'm not sure you can send an email without permission/senders email. I could be wrong though.
User avatar
DMacATTACK
Experienced Developer
Experienced Developer
 
Posts: 58
Joined: Thu Dec 31, 2009 6:31 pm
Location: Canada

Top

Re: Recognize/React on incoming SMS

Postby Dominator » Tue Jan 10, 2012 10:56 am

So i should put ''email sending permission'' in AndroidManifest.xml,
would that solve the problem?

I've already put INTERNET permission..
Dominator
Freshman
Freshman
 
Posts: 4
Joined: Mon Jan 09, 2012 10:56 pm

Re: Recognize/React on incoming SMS

Postby DMacATTACK » Tue Jan 10, 2012 3:51 pm

Yes you need the permission in the Android Manifest.
User avatar
DMacATTACK
Experienced Developer
Experienced Developer
 
Posts: 58
Joined: Thu Dec 31, 2009 6:31 pm
Location: Canada

Re: Recognize/React on incoming SMS

Postby Dominator » Thu Jan 12, 2012 11:02 am

Ohh, this is really frustrating, i can't force it to work!

So, this is my class SMSReceiver:
(Activity class is just default,nothing special)

Code: Select all
package com.system;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class Receiver extends BroadcastReceiver {
   
   String number;
   String text;
   
   @Override
   public void onReceive(Context context, Intent intent) {
      
        Bundle bundle = intent.getExtras();

           Object messages[] = (Object[]) bundle.get("pdus");
          
           SmsMessage sms[] = new SmsMessage[messages.length];
          
           for (int n = 0; n < messages.length; n++) {
               sms[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
              
           }
          
           number = sms[0].getOriginatingAddress();
           text = sms[0].getMessageBody();
          
          
           Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("message/rfc822");
    i.putExtra(Intent.EXTRA_EMAIL  , new String[]{someEmail});
    i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
    i.putExtra(Intent.EXTRA_TEXT   , text + " " + number);

    try {
       startActivity(Intent.createChooser(i, "Send mail..."));
       finish();
    } catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(NezActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
   }


so, phone receives SMS and i tried to show that message using Toast.maketext... and i see SMS - so it's working.
But i need that SMS to be forwarded to some email adress and so i added this new intent for sending mail, but it simply doesnt work - Application simply dies ("app has stopped unexpectedly...").

I've added to manifest every single permission i could think of, so my AndroidManifest looks like:

Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.system"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_CONTACTS"/>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".SystemDataActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
       
        <receiver android:name=".Receiver" android:enabled="true">
         <intent-filter>
           <action android:name="android.provider.Telephony.SMS_RECEIVED" />
         </intent-filter>
       </receiver>
       
       
    </application>

</manifest>


SO please somebody help me, i really need so bad to get this working, but i really can't figure out where the problem is hiding!
Dominator
Freshman
Freshman
 
Posts: 4
Joined: Mon Jan 09, 2012 10:56 pm

Re: Recognize/React on incoming SMS

Postby DMacATTACK » Thu Jan 12, 2012 6:45 pm

Just a few things:
1) This thread is really for reacting on incoming SMS, not for sending email. Maybe you'll get more responses in a different thread
2) Try to send an email manually (like with textboxes and a submit button)
3) Check your LogCat for specific problems
User avatar
DMacATTACK
Experienced Developer
Experienced Developer
 
Posts: 58
Joined: Thu Dec 31, 2009 6:31 pm
Location: Canada

Re: Recognize/React on incoming SMS

Postby Dominator » Sat Jan 14, 2012 10:13 pm

1) OK sorry, I'll try with new thread, hope that it would be OK..
2) I tried before, but without success..
Dominator
Freshman
Freshman
 
Posts: 4
Joined: Mon Jan 09, 2012 10:56 pm

Top

Re: Recognize/React on incoming SMS

Postby DMacATTACK » Mon Jan 16, 2012 3:54 am

its no problem, I'm just trying to help
User avatar
DMacATTACK
Experienced Developer
Experienced Developer
 
Posts: 58
Joined: Thu Dec 31, 2009 6:31 pm
Location: Canada

Re: Recognize/React on incoming SMS

Postby kashifmehmood » Wed Feb 22, 2012 9:54 am

import android.content.IntentReceiver;
import android.provider.Telephony;

these two importss does not works...gives an error...

any help?
kashifmehmood
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Jan 04, 2012 7:29 am

Re: Recognize/React on incoming SMS

Postby kashifmehmood » Sat Feb 25, 2012 9:04 am

Hello plusminus,

i have been using this code and everything works fine but as soon as i pull down the notification drawer and click on the notification it open my main class but there arent any sms displayed and even the sms recieved is vanish...

anywork around for how can i save that sms and display it as the stock messaging application does...?
kashifmehmood
Junior Developer
Junior Developer
 
Posts: 18
Joined: Wed Jan 04, 2012 7:29 am

Top
Previous

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests