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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:16:43+00:00 2026-06-18T02:16:43+00:00

I have an app that I’m trying to set up so that when I

  • 0

I have an app that I’m trying to set up so that when I receive a text containing a certain phrase (Currently set to “This is a test” just to test it), a button onClick event will fire. If my message receiver was in my main activity, I could simply call .performClick(). However, I cant get it to work unless the message receiver is in a seperate class.

MessageReceiver.java

package com.defsoftsol.snow.alert;

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

public class MessageReceiver extends BroadcastReceiver 
{
    public void onReceive(Context context, Intent intent) 
    {
        Bundle pudsBundle = intent.getExtras();
        Object[] pdus = (Object[]) pudsBundle.get("pdus");
        SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);    
        Log.i("MessageBody",  messages.getMessageBody());
        if(messages.getMessageBody().contains("This is a test")) 
        {
            Toast.makeText(context, "It worked", Toast.LENGTH_LONG).show();
        }
    }
}

How can I do a performClick() on a button thats in MainActivity.java? Can I somehow access the View from that class?

manifest entry

<receiver android:name=".MainActivity.MessageReceiver" android:exported="true">
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
    </intent-filter>
</receiver>

Logcat from crash when receive text with receiver in mainactivity.java

01-30 20:31:57.002: E/AndroidRuntime(32555): FATAL EXCEPTION: main
01-30 20:31:57.002: E/AndroidRuntime(32555): java.lang.RuntimeException: Unable to instantiate receiver com.defsoftsol.snow.alert.MainActivity.MessageReceiver: java.lang.ClassNotFoundException: com.defsoftsol.snow.alert.MainActivity.MessageReceiver
01-30 20:31:57.002: E/AndroidRuntime(32555):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2100)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at android.app.ActivityThread.access$1500(ActivityThread.java:123)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1197)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at android.os.Looper.loop(Looper.java:137)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at android.app.ActivityThread.main(ActivityThread.java:4428)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at java.lang.reflect.Method.invokeNative(Native Method)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at java.lang.reflect.Method.invoke(Method.java:511)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at dalvik.system.NativeStart.main(Native Method)
01-30 20:31:57.002: E/AndroidRuntime(32555): Caused by: java.lang.ClassNotFoundException: com.defsoftsol.snow.alert.MainActivity.MessageReceiver
01-30 20:31:57.002: E/AndroidRuntime(32555):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-30 20:31:57.002: E/AndroidRuntime(32555):    at android.app.ActivityThread.handleReceiver(ActivityThread.java:2095)
01-30 20:31:57.002: E/AndroidRuntime(32555):    ... 10 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-18T02:16:44+00:00Added an answer on June 18, 2026 at 2:16 am

    you can make MessageReceiver as a inner class of mainactivity, and then, you can call button.performClick in your mainactivity

    public class MainAcitivity extends Activity
    {
       private Button button;
       ....
    
       ....
    
       public static class MessageReceiver extends BroadcastReceiver 
       {
           public void onReceive(Context context, Intent intent) 
          {
               button.performClick();
          }
       }
    
     }
    
    
    <receiver android:name=".MainActivity$MessageReceiver" android:exported="true">
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
    </intent-filter>
    

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

Sidebar

Related Questions

I have an App that downloads and displays images from URL's. This works fine
I have an app that received JSON data from the server. Currently when I
I just need to play a simple sound, I have app that send messages,
I have an app that is currently on apples App Store. It stores users
I have an app that I am trying to work out. In one layout
I have this app that, on first launch, calls 2 different API endpoints on
I have an app ,that log print something like this: GC_CONCURRENT freed 433k,7% free
I have a app that loads some json from my php web service. This
I have an app that plays audio in the background. I'm trying to use
Have an app that can use tts to read text messages. It can also

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.