如果强制停止,我正在尝试在收到短信时重新启动我的应用程序。这是我的代码。它没有重新启动应用程序。我是否应该尝试将接收器写为另一个类。在清单中:
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<receiver android:name=".MySMSbr">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
My mainActivity onCreate() :
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
BroadcastReceiver SMSbr;
public void onCreate(Bundle savedInstanceState) {
Toast.makeText(getApplicationContext(),"in OnCreate", Toast.LENGTH_LONG).show();
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SMSbr = new BroadcastReceiver()
{
@Override
public void onReceive(Context context,Intent intent)
{
this.abortBroadcast();
Toast.makeText(context, "in onReceive", Toast.LENGTH_LONG).show();
toggleLogging(AppSettings.getServiceRunning(MainActivity.this),
AppSettings.getLoggingInterval(MainActivity.this));
this.clearAbortBroadcast();
}//end of onReceive method
};//end of BroadcastReceiver
IntentFilter SMSfilter = new IntentFilter(SMS_RECEIVED);
this.registerReceiver(SMSbr, SMSfilter);
}
in togglelogging the service is started
where is it going wrong.