Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7060555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:22:01+00:00 2026-05-28T04:22:01+00:00

I wan’t to build SMS triggered app in my android. I know there’s a

  • 0

I wan’t to build SMS triggered app in my android. I know there’s a lot app in the market to do this but I Just want to try it on my own.

My SMS receiver project is working as well as my Caller project. I want to combine them as 1 application but I’m out of idea. can someone give me a hand?

here is the code snippet I got from somewhere and tested working..

Caller.java

package pi.redphone;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;



public class Caller extends Activity 
{
    private Context context;

    /** Called when the activity is first created. */
    @Override
       public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        String num = "2217238";
        call(num);
    } 

 public void call(String number) 
{
    try 
    {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:"+number));
        startActivity(callIntent);
    } 
    catch (ActivityNotFoundException activityException) 
    {
        Log.e("dialing-example", "Call failed", activityException);
    }
}

}

the phone number in the code above is hard coded and it will call to this number after installation 2217238

SmsReceiver.java

package pi.redphone;

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 SmsReceiver extends BroadcastReceiver
{


    public void onReceive(Context context, Intent intent) 
    {
        Bundle bundle = intent.getExtras();
        //SmsMessage msg = null;
        String sender = null;
        String msgBody = null;

        if(bundle != null)
        {
            Object[] sms = (Object[]) bundle.get("pdus");

            for(int i=0; i<sms.length; i++)
            {
                SmsMessage msg = SmsMessage.createFromPdu((byte[]) sms[i]);
                sender = msg.getOriginatingAddress(); //store sender's mobile #
                msgBody = msg.getMessageBody(); //msg content

            }
            Toast.makeText(context, sender, Toast.LENGTH_LONG ).show();


        }

    }

}

after the installation, the app will give this error

The application Callforwarding has stoped working unexpectedly. Pls
try again..

Actually what I want to do is when someone send sms to my android my SmsReceiver will extract the sender mobile number and it will call back.. the sender’s number is stored in theh sender variable..

I want to do something like this

call(sender);

But It’s not easy as that.. I can combine the source code with no errors but I cannot get it working after the installation…

This would be my first Android application if I can get this to work.. 😉


This is my manifest file:

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

    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="android.permission.RECEIVE_SMS">

    </uses-permission>

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".callForward"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

And this is my LogCAt:

01-15 03:11:50.265: I/jdwp(289): Ignoring second debugger -- accepting and dropping
01-15 03:12:30.756: W/KeyCharacterMap(289): No keyboard for id 0
01-15 03:12:30.756: W/KeyCharacterMap(289): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
01-15 03:13:05.095: D/dalvikvm(289): GC_EXPLICIT freed 1347 objects / 90832 bytes in 74ms
01-15 03:18:25.995: D/AndroidRuntime(357): Shutting down VM
01-15 03:18:26.045: W/dalvikvm(357): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-15 03:18:26.115: E/AndroidRuntime(357): FATAL EXCEPTION: main
01-15 03:18:26.115: E/AndroidRuntime(357): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pi.redphone/pi.redphone.callForward}: java.lang.ClassCastException: pi.redphone.callForward
01-15 03:18:26.115: E/AndroidRuntime(357):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-15 03:18:26.115: E/AndroidRuntime(357):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-15 03:18:26.115: E/AndroidRuntime(357):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-15 03:18:26.115: E/AndroidRuntime(357):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-15 03:18:26.115: E/AndroidRuntime(357):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 03:18:26.115: E/AndroidRuntime(357):  at android.os.Looper.loop(Looper.java:123)
01-15 03:18:26.115: E/AndroidRuntime(357):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-15 03:18:26.115: E/AndroidRuntime(357):  at java.lang.reflect.Method.invokeNative(Native Method)
01-15 03:18:26.115: E/AndroidRuntime(357):  at java.lang.reflect.Method.invoke(Method.java:521)
01-15 03:18:26.115: E/AndroidRuntime(357):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-15 03:18:26.115: E/AndroidRuntime(357):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-15 03:18:26.115: E/AndroidRuntime(357):  at dalvik.system.NativeStart.main(Native Method)
01-15 03:18:26.115: E/AndroidRuntime(357): Caused by: java.lang.ClassCastException: pi.redphone.callForward
01-15 03:18:26.115: E/AndroidRuntime(357):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-15 03:18:26.115: E/AndroidRuntime(357):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-15 03:18:26.115: E/AndroidRuntime(357):  ... 11 more
01-15 03:18:35.085: I/Process(357): Sending signal. PID: 357 SIG: 9
01-15 03:31:01.475: D/AndroidRuntime(449): Shutting down VM
01-15 03:31:01.505: W/dalvikvm(449): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-15 03:31:01.555: E/AndroidRuntime(449): FATAL EXCEPTION: main
01-15 03:31:01.555: E/AndroidRuntime(449): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pi.redphone/pi.redphone.callForward}: java.lang.ClassCastException: pi.redphone.callForward
01-15 03:31:01.555: E/AndroidRuntime(449):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
01-15 03:31:01.555: E/AndroidRuntime(449):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
01-15 03:31:01.555: E/AndroidRuntime(449):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-15 03:31:01.555: E/AndroidRuntime(449):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-15 03:31:01.555: E/AndroidRuntime(449):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 03:31:01.555: E/AndroidRuntime(449):  at android.os.Looper.loop(Looper.java:123)
01-15 03:31:01.555: E/AndroidRuntime(449):  at android.app.ActivityThread.main(ActivityThread.java:4627)
01-15 03:31:01.555: E/AndroidRuntime(449):  at java.lang.reflect.Method.invokeNative(Native Method)
01-15 03:31:01.555: E/AndroidRuntime(449):  at java.lang.reflect.Method.invoke(Method.java:521)
01-15 03:31:01.555: E/AndroidRuntime(449):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-15 03:31:01.555: E/AndroidRuntime(449):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-15 03:31:01.555: E/AndroidRuntime(449):  at dalvik.system.NativeStart.main(Native Method)
01-15 03:31:01.555: E/AndroidRuntime(449): Caused by: java.lang.ClassCastException: pi.redphone.callForward
01-15 03:31:01.555: E/AndroidRuntime(449):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
01-15 03:31:01.555: E/AndroidRuntime(449):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
01-15 03:31:01.555: E/AndroidRuntime(449):  ... 11 more
01-15 03:31:15.255: I/Process(449): Sending signal. PID: 449 SIG: 9

The application still don’t run. here is my whole source code.

package pi.redphone;

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 callForward extends BroadcastReceiver
 {
    /** Called when the activity is first created. */
    public void onReceive(Context context, Intent intent) 
    {
        Bundle bundle = intent.getExtras();
        //SmsMessage msg = null;
        String sender = null;
        String msgBody = null;

        if(bundle != null)
        {
            Object[] sms = (Object[]) bundle.get("pdus");

            for(int i=0; i<sms.length; i++)
            {
                SmsMessage msg = SmsMessage.createFromPdu((byte[]) sms[i]);
                sender = msg.getOriginatingAddress(); //store sender's mobile #
                msgBody = msg.getMessageBody(); //msg content

            }
            Toast.makeText(context, sender, Toast.LENGTH_LONG ).show();


        }

    }

}

I have a feeling that the code is correct but I cannot figure out how to solve the issue..


I don’t know how to follow your suggestion because I’m always getting error. but instead help me to check if I’m doing right..

this is my latest code. call is functioning but my sms receiver don’t.

I dont know how to call my

public class SmsReceiver extends BroadcastReceiver 

in the activity so that it listen to incoming sms.

Call4wardActivity.Java

package pi.redphone;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.util.Log;
import android.widget.Toast;

public class Call4wardActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            call();

        }



    public void call() 
    {
        try {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:123456789"));
            startActivity(callIntent);
        } catch (ActivityNotFoundException activityException) {
             Log.e("helloandroid dialing example", "Call failed", null);
        }
    }

    public class SmsReceiver extends BroadcastReceiver 
    {


        @Override
        public void onReceive(Context context, Intent intent) 
        {
            // TODO Auto-generated method stub
            Bundle bundle = intent.getExtras();        
            SmsMessage[] msgs = null;
           // String body = null;
            String sender = null;


            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]);  
                    sender = msgs[i].getOriginatingAddress();

                }
                //---display the new SMS message---
                Toast.makeText(context, sender, Toast.LENGTH_LONG).show();

            }                       
        }

        }


    }

manifest file

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

    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CALL_PHONE"/>


    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Call4wardActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>

    <uses-permission android:name="android.permission.CALL_PHONE"/>

</manifest>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:22:01+00:00Added an answer on May 28, 2026 at 4:22 am

    You’ll have to post your logcat error for help with the crashing. But making a phone call isn’t too hard. My initial guess is that you are missing permissions in your android manifest. Does it have all the permissions from the SMS and Dialer apps?

    Make sure that sender is storing only a phone number. I believe it is though.

    You really don’t need to include the first application. The only code you need is

    try  
    {  
        Intent callIntent = new Intent(Intent.ACTION_CALL);  
        callIntent.setData(Uri.parse("tel:"+number));  
        startActivity(callIntent);  
    }   
    catch (ActivityNotFoundException activityException)   
    {  
        Log.e("dialing-example", "Call failed", activityException);  
    }  
    

    Replace number with sender and you should be all set.

    If you want to keep both Activities you can do the following.
    Intent callIntent = new Intent(this, Caller.class );
    callIntent.putExtra(“phoneNumber”, sender);
    startActivity(callIntent);

    In the call activity, you would

    Bundle extras = getIntent().getExtras();  
    string sender = extras.getInt("phoneNumber");  
    

    Then you can prompt the user and ask if u want the app to call the number. Or you can just call it right away. If you’re just calling the # right away without confirmation, use the 1st solution mentioned above in my post.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wan't to use this controll in my app but cant find which it
i wan't to know if there is a way to decrease the Run Speed
I wan to know if there is a better way to handle sql bursts
I am new to Perl and I wan to know whether there is an
I wan't to do this using Mono, but Mono is so transparent the question
I wan to monitor changes in android system file /sys/class/net/eth0/operstate for monitoring ethernet state.
Lets say I wan't to add 1 to an integer. This will only be
I wan't to animate a view that's shaped as an arrow, and I want
i wan to disable drag event using jquery and want to bind one another
i wan't to know how to generate thumbnails with phpThumb Class, with an array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.