关闭广播接收器

时间:2017-03-20 18:05:51

标签: java android

我希望在关闭手机之前将短信发送给某人的手机。这是广播接收器,但它不起作用。

 public class SwitchOff extends BroadcastReceiver {
 SharedPreferences sharedPreferences;
 public SwitchOff() {
    super();
  }

 @Override
 public void onReceive(Context context, Intent intent) {
    sendSMS(sharedPreferences.getString("number", "error"), "Child Name:" + 
 sharedPreferences.getString("childName", "Service child Name not found") +
            "\nStatus: Mobile is being turned off");
    Toast.makeText(context, "i am going to turned off",     
 Toast.LENGTH_SHORT).show();
 }
 private void sendSMS(String phoneNumber, String message) {
    SmsManager smsManager = SmsManager.getDefault();
    smsManager.sendTextMessage(phoneNumber, null, message, null,
            null);
  }
}

这是我的清单

<receiver
    android:name=".SwitchOff"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.ACTION_SHUTDOWN" />
        <action android:name="android.intent.action.QUICKBOOT_POWEROFF"     
        />
    </intent-filter>
</receiver>

0 个答案:

没有答案
相关问题