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 8948329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:57:25+00:00 2026-06-15T12:57:25+00:00

I have a problem about sending sms in android. I have two classes. one

  • 0

I have a problem about sending sms in android. I have two classes. one of them is SendMessage.java and other one is SendingSms.java and I want to send my messages by SendingSms.java file so there is a sendSms class in it and I want to use this sendSms function in SendMessage.java file but it couldn’t be. In addition I can use function that is in SendingSms.java but when I wrote send sms codes in it, it doesn’t work. What’s the problem?

here is function that is in my SendMessage.java

public void sendMessageButton (View view)
{
    //SendingSms send = new SendingSms();       
    if(who_detail.getText().toString().length()>0 && message_text.getText().toString().length()>0 )
    {
        sendSMS(who_detail.getText().toString(), message_text.getText().toString());

    }
    else
    {
    Toast.makeText(getApplicationContext(), R.string.sendingsms_error, Toast.LENGTH_LONG).show();
    }


}

here is my sendinSms.java

package com.example.stildeneme;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telephony.SmsManager;
import android.widget.Toast;

public class SendingSms extends Activity {

     public void sendSMS(String telNo, String mesaj)
        {
            String SENT = "SMS_SENT";
            String DELIVERED = "SMS_DELIVERED";

            PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);

            PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);

            registerReceiver(new BroadcastReceiver() {

                @Override
                public void onReceive(Context arg0, Intent arg1) {
                    // TODO Auto-generated method stub
                    switch(getResultCode())
                    {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS Gönderildi",Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                         Toast.makeText(getBaseContext(), "Generic failure",Toast.LENGTH_SHORT).show();
                         break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                         Toast.makeText(getBaseContext(), "No service",Toast.LENGTH_SHORT).show();
                         break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU",Toast.LENGTH_SHORT).show();
                        break;                  
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off",Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            }, new IntentFilter(SENT));


            registerReceiver(new BroadcastReceiver(){
                @Override
                public void onReceive(Context arg0, Intent arg1) {
                    switch (getResultCode())
                    {
                        case Activity.RESULT_OK:
                            Toast.makeText(getBaseContext(), "SMS iletildi",
                                    Toast.LENGTH_SHORT).show();
                            break;
                        case Activity.RESULT_CANCELED:
                            Toast.makeText(getBaseContext(), "SMS iletilemedi",
                                    Toast.LENGTH_SHORT).show();
                            break;
                    }
                }

            }, new IntentFilter(DELIVERED));       

            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(telNo, null, mesaj, sentPI, deliveredPI);

         Toast.makeText(getApplicationContext(), telNo.toString() + " - " + mesaj.toString(), Toast.LENGTH_LONG).show();
        }

}

By the way, i extended my SendMessage class from SendingSms class.

here is my logcat

11-30 09:48:09.613: E/AndroidRuntime(1007): FATAL EXCEPTION: main
11-30 09:48:09.613: E/AndroidRuntime(1007): java.lang.IllegalStateException: Could not execute method of the activity
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.view.View$1.onClick(View.java:2144)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.view.View.performClick(View.java:2485)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.view.View$PerformClick.run(View.java:9080)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.os.Handler.handleCallback(Handler.java:587)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.os.Looper.loop(Looper.java:123)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.app.ActivityThread.main(ActivityThread.java:3683)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at java.lang.reflect.Method.invokeNative(Native Method)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at java.lang.reflect.Method.invoke(Method.java:507)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at dalvik.system.NativeStart.main(Native Method)
11-30 09:48:09.613: E/AndroidRuntime(1007): Caused by: java.lang.reflect.InvocationTargetException
11-30 09:48:09.613: E/AndroidRuntime(1007):     at java.lang.reflect.Method.invokeNative(Native Method)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at java.lang.reflect.Method.invoke(Method.java:507)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.view.View$1.onClick(View.java:2139)
11-30 09:48:09.613: E/AndroidRuntime(1007):     ... 11 more
11-30 09:48:09.613: E/AndroidRuntime(1007): Caused by: java.lang.SecurityException: Sending SMS message: User 10048 does not have android.permission.SEND_SMS.
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.os.Parcel.readException(Parcel.java:1322)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.os.Parcel.readException(Parcel.java:1276)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at com.android.internal.telephony.ISms$Stub$Proxy.sendText(ISms.java:369)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at android.telephony.SmsManager.sendTextMessage(SmsManager.java:87)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at com.example.stildeneme.SendingSms.sendSMS(SendingSms.java:69)
11-30 09:48:09.613: E/AndroidRuntime(1007):     at com.example.stildeneme.SendMessage.sendMessageButton(SendMessage.java:76)
11-30 09:48:09.613: E/AndroidRuntime(1007):     ... 14 more
  • 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-06-15T12:57:27+00:00Added an answer on June 15, 2026 at 12:57 pm

    Make the method as public static which you are going to access from another activity. then
    call it as activity1.sendsms();

    This is the way . if you post the code will advice you better way… hope this will help you .

    Hi use the below code. the thing is you need to use Context.

    import android.app.Activity;
    import android.app.PendingIntent;
    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.content.IntentFilter;
    import android.os.Bundle;
    import android.telephony.SmsManager;
    import android.widget.Toast;
    
    public class SendingSms extends Activity {
    
        static Context context;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            context=this;
    
        }
    
         public static void sendSMS(String telNo, String mesaj)
            {
                String SENT = "SMS_SENT";
                String DELIVERED = "SMS_DELIVERED";
    
                PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent(SENT), 0);
    
                PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent(DELIVERED), 0);
    
                context.registerReceiver(new BroadcastReceiver() {
    
                    @Override
                    public void onReceive(Context arg0, Intent arg1) {
                        // TODO Auto-generated method stub
                        switch(getResultCode())
                        {
                        case Activity.RESULT_OK:
                            Toast.makeText(context, "SMS Gönderildi",Toast.LENGTH_SHORT).show();
                            break;
                        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                             Toast.makeText(context, "Generic failure",Toast.LENGTH_SHORT).show();
                             break;
                        case SmsManager.RESULT_ERROR_NO_SERVICE:
                             Toast.makeText(context, "No service",Toast.LENGTH_SHORT).show();
                             break;
                        case SmsManager.RESULT_ERROR_NULL_PDU:
                            Toast.makeText(context, "Null PDU",Toast.LENGTH_SHORT).show();
                            break;                  
                        case SmsManager.RESULT_ERROR_RADIO_OFF:
                            Toast.makeText(context, "Radio off",Toast.LENGTH_SHORT).show();
                            break;
                        }
                    }
                }, new IntentFilter(SENT));
    
    
                context. registerReceiver(new BroadcastReceiver(){
                    @Override
                    public void onReceive(Context arg0, Intent arg1) {
                        switch (getResultCode())
                        {
                            case Activity.RESULT_OK:
                                Toast.makeText(context, "SMS iletildi",
                                        Toast.LENGTH_SHORT).show();
                                break;
                            case Activity.RESULT_CANCELED:
                                Toast.makeText(context, "SMS iletilemedi",
                                        Toast.LENGTH_SHORT).show();
                                break;
                        }
                    }
    
                }, new IntentFilter(DELIVERED));       
    
                SmsManager sms = SmsManager.getDefault();
                sms.sendTextMessage(telNo, null, mesaj, sentPI, deliveredPI);
    
             Toast.makeText(context, telNo.toString() + " - " + mesaj.toString(), Toast.LENGTH_LONG).show();
            }
    
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem about div position relative alignment. I want the second div
I have a great problem about the rotation in three.js I want to rotate
I'm developing a mobile applicatiom for symbian but I have a problem about sending
I'm having this problem: I have two Google maps in one page, showing just
I have got problem with sending int from Java Client to C++ server. I
I have a problem about casting a CallableStatement to OracleCallableStatement . It gives ClassCastException
I am using MFC CFile Seek function. I have a problem about Seek out
I have a little problem about the sort direction of a specific column in
I have a little problem about Google Maps. I'm using Geocoding (xml) for getting
I have a little problem about using jQuery (I really do not know jQuery

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.