I am working on an application in which, when I receive a message, I need to start the service. But my Intent service is not working. That's what I'm doing:
Broadcast Receiver:
public void onReceive(Context context, Intent intent) { this.con=context; Toast.makeText(context,"Broadcast received", Toast.LENGTH_LONG).show(); Bundle bundle = intent.getExtras(); Object[] messages = (Object[])bundle.get("pdus"); SmsMessage[] sms = new SmsMessage[messages.length]; for(int i=0;i<messages.length;i++) { sms[i] = SmsMessage.createFromPdu((byte[]) messages[i]); } String smsFrom = sms[0].getDisplayOriginatingAddress().toString(); Intent in= new Intent(context, ResponseService.class); in.putExtra("sender",smsFrom); context.startService(in); }
IntentService:
public class ResponseService extends IntentService { public ResponseService(String name) { super(name);
Nothing happens in the log file. can someone please help me understand the problem? Thanks in advance.
Update I already declared both the broadcast receiver and the service in manifest.xml as follows:
<receiver android:name=".BroadCastReceiver" > <intent-filter android:priority="10000" > <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> <service android:name=".ResponseService" />
Also, I tried to run the application again, and after a while the application closed the application giving java.lang.instantiationexception Can someone please help me with this problem?
Guria source share