Soru & Cevap

Android Web Servis

01.02.2017 - 05:23
package com.example.aysenur.sekretertakip;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private SharedPreferences loginPreferences;
    private SharedPreferences.Editor loginPrefsEditor;

    EditText txtfirmaKodu,txtkullaniciAdi,txtsifre;
    Button btngiris,btncikis;
    Spinner spinnerFirma;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        txtkullaniciAdi = (EditText) findViewById(R.id.etkullanici);
        txtsifre = (EditText) findViewById(R.id.etsifre);
        txtfirmaKodu = (EditText) findViewById(R.id.etfirma);

        final CheckBox cbHatirla = (CheckBox) findViewById(R.id.cbHatirla);
 

        btngiris = (Button) findViewById(R.id.btngiris);
        btncikis = (Button) findViewById(R.id.btncikis);

        loginPreferences = getSharedPreferences("loginPrefs",MODE_PRIVATE);
        loginPrefsEditor = loginPreferences.edit();
        Boolean hatirla = loginPreferences.getBoolean("hatirla",false);

        if (hatirla==true){

            txtkullaniciAdi.setText(loginPreferences.getString("kullaniciAdi",""));
            txtsifre.setText(loginPreferences.getString("sifre",""));
            cbHatirla.setChecked(true);
        }
        btngiris.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<String> list = WebServiceProcesses.KullaniciGirisi(txtfirmaKodu.getText().toString(),txtkullaniciAdi.getText().toString(),txtsifre.getText().toString());
                if (list.size() == 1){
                    Session.firmaID = Integer.parseInt(list.get(0));
                    Session.kullaniciID = Integer.parseInt(txtfirmaKodu.getText().toString());
                    if (cbHatirla.isChecked()){
                        loginPrefsEditor.putBoolean("hatirla",true);
                        loginPrefsEditor.putString("kullaniciAdi",txtkullaniciAdi.getText().toString());
                        loginPrefsEditor.putString("sifre",txtsifre.getText().toString());
                        loginPrefsEditor.commit();
                    }
                    else {
                        loginPrefsEditor.clear();
                        loginPrefsEditor.commit();
                    }
                    startActivity(new Intent(MainActivity.this,AnaSayfa.class));
                } else {
                    Toast.makeText(getApplicationContext(),"Hatalı Bilgiler Girdiniz" , Toast.LENGTH_LONG).show();
                }
            }
        });
        btncikis.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}

Arkadaşlar ben bir tane login ekranlı uygulama yapmak istiyorum.Ancak web servisten bilgileri çekmiyor.Null olarak döndürüyor.

package com.example.aysenur.sekretertakip;

import android.os.StrictMode;
import android.util.Pair;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.MarshalFloat;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by AYSENUR on 30/01/2017.
 */

public class WebServiceProcesses {
    private static String NAMESPACE = "http://tempuri.org/";
    private static String URL = "http://elazigyoreselmarket.com/WebServiceSekreterTakip/service1.asmx";
    private static SoapSerializationEnvelope startProcess(String namespace, List<Pair<String,Object>> list ,boolean marshal){
        SoapObject request = new SoapObject(NAMESPACE,namespace);
        if (list != null)
            for (int i =0 ; i<list.size();i++)
                request.addProperty(list.get(i).first,list.get(i).second);
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        if (marshal){
            envelope.implicitTypes = true;
            envelope.encodingStyle = SoapSerializationEnvelope.XSD;
            MarshalFloat mf = new MarshalFloat();
            mf.register(envelope);
        }
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        return envelope;
    }
    public static List<String> KullaniciGirisi(String firmaID, String kullaniciAdi,String sifre){
        String nameSpace = "KullaniciGirisi";
        List<String> listString = new ArrayList<>();
        List<Pair<String,Object>> pairList = new ArrayList<>();
        pairList.add(new Pair<String, Object>("firmaID",firmaID));
        pairList.add(new Pair<String, Object>("kullaniciAdi",kullaniciAdi));
        pairList.add(new Pair<String, Object>("sifre",sifre));
        SoapSerializationEnvelope envelope = startProcess(nameSpace,pairList,false);
        HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
        httpTransportSE.debug=true;

        try {
            httpTransportSE.call("http://tempuri.org/" + nameSpace,envelope);
            SoapObject response = (SoapObject) envelope.getResponse();
            if (!(response.toString().equals("anyType {}") || response ==null)){
                int rowCount = response.getPropertyCount();
                for (int i =0;i<rowCount;i++){
                    listString.add(response.getProperty(i).toString());
                }
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
        return listString;
    }


}

Bu da web servis bağlantısı.Yardımcı olursanız sevinirim.

Teşekkürler

26 Görüntülenme

1 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-32814-1494668919.jpg
fyeilyurt
04.02.2017 - 01:37

burada güzel yapmış dayının biri

 

http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/

Ayşenur Toprak
06.02.2017 - 10:02
bu json ve sqlite ile yapmış.Ben ksoap ile yapmaya çalışıyorum.Biraz farklı bu.