我正在接收消息,我需要启动服务的应用程序。但是我的意图服务没有运行。下面是我在做什么:意图服务不从广播接收器调用时开始
广播接收器:
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);
// TODO Auto-generated constructor stub
}
@Override
protected void onHandleIntent(Intent intent)
{
// TODO Auto-generated method stub
Log.d("Notify", "In Response Service");
getCurrentLocation();
}
}
我不明白在日志文件中任何东西。任何人都可以帮助我理解这个问题吗?提前致谢。
更新 我已经宣布的manifest.xml两个广播接收器和服务如下:
<receiver android:name=".BroadCastReceiver" >
<intent-filter android:priority="10000" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<service android:name=".ResponseService" />
而且我再次尝试运行应用程序,并经过一段时间的应用程序强制关闭给一个java .lang.instantiationexception 有人可以帮我解决这个问题吗?
yes吐司正在显示,我已经在清单中声明了收件人。接收器工作得很好。 – Guria
然后你的意图服务不起作用。一定要声明'ResponseService',就像我在我的答案中声明的一样。 – longwalker
我也宣布过 – Guria