スケジュールされたSMSを送信するコードが動作しません.SMSは10秒後に送信されません.WHY?SmsManagerとAllarmAlertは動作しません
私はあなたに私のコードを示しています。
MainActivity:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void scheduleAlarm(View V){
//Long time= new GregorianCalendar().getTimeInMillis()+24*60*60*1000;
//Long time= new GregorianCalendar().getTimeInMillis()+10000;
//Long time= System.currentTimeMillis() + 10000;
Intent intentAlarm= new Intent(this, AlarmReceiver.class);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
//alarmManager.set(AlarmManager.RTC_WAKEUP, time, PendingIntent.getBroadcast(this, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 10000, PendingIntent.getBroadcast(this, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
Toast.makeText(this, "Alarm Scheduled", Toast.LENGTH_LONG).show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
BroadcastReceiver:事前に
public class AlarmReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String phoneNumberReciver="1234556";
String message="blablabla";
android.telephony.SmsManager sms= SmsManager.getDefault();
sms.sendTextMessage(phoneNumberReciver, null, message, null, null);
Toast.makeText(context, "Alarm Triggered and SMS Sent", Toast.LENGTH_LONG);
}
}
ありがとう!
brodcast受信機からSMSを送信が、意図サービス –