Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Build SMS Receiver module

$
0
0

Hi guys, i was developing native for getting the sms notification and read the content

i was creating this class, but whenever i build the module and install it to titanium apps, the app will always crash after receive any sms, with this error

Sending event: exception on thread: main msg:java.lang.RuntimeException: Unable to instantiate receiver com.example.test.IncomingSms: java.lang.ClassNotFoundException: Didn't find class "com.example.smslistener.test" on path:....
Here the native code:
public class IncomingSms extends BroadcastReceiver {
 
    // Get the object of SmsManager
    final SmsManager sms = SmsManager.getDefault();
 
    public void onReceive(Context context, Intent intent) {
 
        final Bundle bundle = intent.getExtras();
        try {
 
            if (bundle != null) {
 
                final Object[] pdusObj = (Object[]) bundle.get("pdus");
 
                for (int i = 0; i < pdusObj.length; i++) {
 
                    SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
                    String phoneNumber = currentMessage.getDisplayOriginatingAddress();
 
                    String senderNum = phoneNumber;
                    String message = currentMessage.getDisplayMessageBody();
 
                    Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);
 
 
                   // Show Alert
                    int duration = Toast.LENGTH_LONG;
                    Toast toast = Toast.makeText(context, 
                                 "senderNum: "+ senderNum + ", message: " + message, duration);
                    toast.show();
 
                } // end for loop
              } // bundle is null
 
        } catch (Exception e) {
            Log.e("SmsReceiver", "Exception smsReceiver" +e);
 
        }
    }    
}
and this is what i included on tiApp.xml
<application>
                <receiver android:name="com.example.test.IncomingSms">
                    <intent-filter>
                        <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
                    </intent-filter>
                </receiver>
            </application>
thanks for the help

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>