Merhab Ömer Bey,
Öncelikle cevabınız için teşekkür ederim, Switch'den konum bilgisini nasıl alacağım bulamadım. java kodunu vereyim bakarsanız sevinirim. Android konusunda yeniyim ilk denemem bu.
Saygılarımla.
JAVA KOD;
package com.mursavasyandex.gsm_kontrol;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity
{
Switch Sw1,Sw2;
TextView tv;
SharedPreferences preferences;
boolean a,b;
@Override
protected void onPause() {
SharedPreferences.Editor editor=preferences.edit();
editor.putBoolean("Buton_Durumu_1",Sw1.getSplitTrack());
editor.putBoolean("Buton_Durumu_2", Sw2.getSplitTrack());
editor.commit();
Toast.makeText(this,"Data Saved",Toast.LENGTH_LONG).show();
super.onPause();
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Sw1 = (Switch)findViewById(R.id.RL1);
Sw2 = (Switch)findViewById(R.id.RL2);
tv = (TextView)findViewById(R.id.textView);
preferences= PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
preferences.getBoolean("Buton_Durumu_1", Sw1.isChecked());
preferences.getBoolean("Buton_Durumu_2",Sw2.isChecked());
Sw1.setChecked(a);
Sw2.setChecked(b);
Sw1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage("+90555555555”, null, "_1AC", null, null);
tv.setText("1 Ac sinyali Gönderildi!!!");
} else {
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage("+905331373878", null, "_1KP", null, null);
tv.setText("1 Kapat sinyali Gönderildi!!!");
}
}
});
Sw2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if (isChecked)
{
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage("+90555555555",null,"_2AC",null,null);
tv.setText("2 Ac sinyali Gönderildi!!!");
}
else
{
SmsManager manager = SmsManager.getDefault();
manager.sendTextMessage("555555555",null,"_2KP",null,null);
tv.setText("2 Kapat sinyali Gönderildi!!!");
}
}
});
}
}