简体   繁体   中英

SMS Broadcasting from my app

I want to send an SMS Broadcast from my app. I didn't think it was possible until I came across this article.

http://blog.dev001.net/post/14085892020/android-generate-incoming-sms-from-within-your-app

I followed the instructions the author gave. The author, however, didn't include the GsmAlphabet piece. He does supply the URL to the source and gives a brief summary what you need to adjust. I have not had success. I tried contacting him but he said he no longer had the code on his PC. I created a new class and pasted in the source. I used my package. I changed the Exceptions to generics. There was some char to string issues that I fixed with Character.toString. There was some String.Empty() errors that I changed to equals(""). I commented out the center SmsMessageBase portion b/c it was showing errors, appeared to be contained, and didn't tie into what the author's function was fetching. I switched the array-integers populated by the resources "R" to new int[0]...because that's what it looks like the value is in http://source-android.frandroid.com/frameworks/base/core/res/res/values/config.xml . When I run it I don't get any errors...just nothing appears to happen.

Then a day or so later I noticed Handcent saying I had a couple new messages in my notification bar. They were from my test number but upon viewing they said "invalid format." They didn't show up in the inbox after the notification was cleared.

I was hoping someone might have the GsmAlphabet piece so I can see what I may have incorrect. I have spent a lot of time on this already and am hopeful I can get this to work. Someone has touched on this a little in stackoverflow:

Permission denial on BroadCast SMS intent

I am tested with Android 2.3.3.

GsmAlphabet link is above. You copy EncodeException . It's work perfectly but I find that in Android4.1 they change GsmAlphabet so it doesn't running. If you use GsmAlphabet for Android2.2 it still work at Android3.0

Edit: Another solution is using reflection to access

try {
            String sReflectedClassName = "com.android.internal.telephony.GsmAlphabet";
            Class cReflectedNFCExtras = Class.forName(sReflectedClassName);
            Method stringToGsm7BitPacked = cReflectedNFCExtras.getMethod(
                    "stringToGsm7BitPacked", new Class[] { String.class });
            stringToGsm7BitPacked.setAccessible(true);
            byte[] bodybytes = (byte[]) stringToGsm7BitPacked.invoke(null,
                    body);
            bo.write(bodybytes);
        } catch (Exception e) {
        }

你可以在这里找到GsmAlphabet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM