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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:25:00+00:00 2026-06-05T10:25:00+00:00

Hi everyone I have really important question please help me. I’m trying to handle

  • 0

Hi everyone I have really important question please help me.
I’m trying to handle incoming messages with broadcastReceiver.However,it does not work.I send the code below please help me.

My Manifest:

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

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

    <uses-permission  android:name="android.permission.SEND_SMS"/>
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.BROADCAST_SMS"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>



    <application
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
         <receiver android:name=".SMSBroadcastReceiver">
           <intent-filter android:priority="999">
                <action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
            </intent-filter>
        </receiver>
        <activity
            android:name=".NewPage"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".NewMessage" />
        <activity android:name=".SignFrame"></activity>
        <activity android:name=".MyMenu"></activity>
        <activity android:name=".Detail"></activity>
        <activity android:name=".Browser"></activity>
        <activity android:name=".Login"></activity>
        <activity android:name=".UserDetail"></activity>
        <activity android:name=".AndroidAppActivity"></activity>
    </application>

</manifest>




My Class:


package com.commonsware.andorid;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.acl.Owner;
import java.util.StringTokenizer;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract.PhoneLookup;
import android.telephony.SmsMessage;

import android.util.Log;
import android.widget.Toast;

public class SMSBroadcastReceiver extends BroadcastReceiver {




        private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
        private static final String TAG = "SMSBroadcastReceiver";
        RSA rsa;
        DataBaseHelper db;
        @Override
        public void onReceive(Context context, Intent intent) {
            try {
                rsa=new RSA();
            } catch (InvalidKeyException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (NoSuchAlgorithmException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IllegalBlockSizeException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (NoSuchProviderException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (BadPaddingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (NoSuchPaddingException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (FileNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
             Log.i(TAG, "Intent recieved: " + intent.getAction());

             if (intent.getAction().equals(SMS_RECEIVED)) {
                abortBroadcast();
                    Bundle bundle = intent.getExtras();
                    if (bundle != null) {
                        Object[] pdus = (Object[])bundle.get("pdus");
                        final SmsMessage[] messages = new SmsMessage[pdus.length];
                        for (int i = 0; i < pdus.length; i++) {
                            messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                        }
                        if (messages.length > -1) {
                            abortBroadcast();
                            Toast toast =Toast.makeText(context, messages.toString(), Toast.LENGTH_LONG);
                            String body = messages[0].getMessageBody().toString();
                            String address = messages[0].getOriginatingAddress();
                            System.out.println(address);
                            String decrypted = null;

                            toast.show();
                            Intent i = new Intent(context, Detail.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(i); 
                            try {
                                decrypted=rsa.decrypt(body.getBytes());

                            } catch (InvalidKeyException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (IllegalBlockSizeException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (BadPaddingException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (NoSuchAlgorithmException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (NoSuchPaddingException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            Log.i(TAG, "Message recieved: " + messages[0].getMessageBody());
                            if(body.startsWith("<publicKey>")){
                                createContact(messages[0]);

                            }
                            else if(body.startsWith("<secureSmsMessaging>")){
                            createMessage(messages[0]);
                            }
                            messages[0].getMessageBody().replaceAll(body, decrypted);


                        }
                    }
                }

                this.abortBroadcast();
           }
}

I tried to debug it.But it does not enter into my broadcastreceiver .Whenever I send a message Android’s default messaging service handles it.What am I doing wrong?

I’m waiting for your answer.Thanks.

Sevil.

  • 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-05T10:25:01+00:00Added an answer on June 5, 2026 at 10:25 am

    I solved my problem by using an https server.My problem was converting a string that contains a byte array into byte array during sending the user’s public key and encrypted messages.Now I’m using a https server to write my staffs and then read from there.It is now more economic.I recommend everyone to use https server who wants to provide encryption in messaging since you may encounter many problem.

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

Sidebar

Related Questions

Thank everyone for the help I have made some really good changes but now
Hello everyone, I have been banging my head really hard trying to solve this
Now I do have a hw question for everyone...I've been staring at this for
Good day everyone. I have a question regarding drawing libraries for C#. I always
I have been really puzzled because I was trying to work out some jQuery
Everyone, I have really tried, but I can't find out how to upload photos
Hi everyone I have a really strange problem. I create a new subclass of
I have a central git repository that everyone pushes to for testing and integration,
Hi everyone my problem today is I have a couple of buttons that slide
Hello everyone Masters Of Web Delevopment :) I have a piece of PHP script

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.