0

내 원시 응용 프로그램 구축 프로세스의 일부인 로그인 응용 프로그램을 작성했습니다. 로그인 세션을 사용하는 끝 점이 거의 없습니다. 로그인 끝점에 대한 성공적인 결과가 나타납니다. 예를 들면 다음과 같습니다. 사용자가 로그인 한 경우 추가 활동에서 나머지 기능에 액세스 할 수 있습니다. 그러나 활동을 전환하려고 시도하는 동안 "로그인해야하는 사용자 요구 사항"이 표시됩니다.클라이언트가 활동을 변경하면 자동으로 처리하는 HTTP 연결을 만드는 방법

MainActivity.java

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     jsonResponse = new LoginPOJO(); 

     // UserLogin Field 
     etUserName = (EditText) findViewById(R.id.etUserName); 
     // UserLogin Password 
     etPassword = (EditText) findViewById(R.id.etPassword); 
     // Login Button Image 
     btnLogin = (ImageView) findViewById(R.id.btnLogin); 
     btnLogin.setOnClickListener(this); 
     // User SignUp Button Image 
     ImageView btnSignUp = (ImageView) findViewById(R.id.btnSignUp); 
     btnSignUp.setOnClickListener(this); 
     // Forget Password Textbutton 
     TextView frgtPassword = (TextView) findViewById(R.id.forgetpassword); 
     frgtPassword.setOnClickListener(this); 
     // Skip for now button 
     final TextView skipfornow = (TextView) findViewById(R.id.skipnow); 
     skipfornow.setOnClickListener(this); 

     } 
private void logIn(final String username, final String password) { 
     final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); 
     progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
     progressDialog.setMessage("Logging you in..."); 
     progressDialog.setIndeterminate(true); 
     progressDialog.setCancelable(false); 
     progressDialog.show(); 
     String UPLOAD_URL = "http://xxxxx-dev.elasticbeanstalk.com/api/v1/login"; 
     final StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL, 
       new Response.Listener<String>() { 
        @Override 
        public void onResponse(String s) { 
         //Dismissing the progress dialog 
         progressDialog.dismiss(); 
         // Getting the final Json Object 
         JSONObject parentObject; 
         try { 
          parentObject = new JSONObject(s); 

          LoginPOJO.setCode(parentObject.getString("code")); 

          // Getting the data from Data Json Object 
          JSONObject dataObject = parentObject.getJSONObject("data"); 

          // Getting data from Geo object 
          JSONObject geoObject = dataObject.getJSONObject("geo"); 

          // Getting data from businesses Array 
          JSONArray businessesArray = dataObject.getJSONArray("businesses"); 

          // Getting data from Meta Object 
          JSONObject metaObject = parentObject.getJSONObject("meta"); 

          startActivity(new Intent(MainActivity.this, PromotionsFeedActivity.class)); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
         //Showing toast message of the response 
         Log.i("TAG", "onResponse: " + s); 

        } 
       }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError volleyError) { 
         //Dismissing the progress dialog 
         progressDialog.dismiss(); 
         //Showing snackbar 
         Toast.makeText(MainActivity.this, "Connection Problem", Toast.LENGTH_SHORT).show(); 
        } 
       }) { 
      @Override 
      protected Map<String, String> getParams() throws AuthFailureError { 
       //Converting Bitmap to String 
       //Creating parameters 
       Map<String, String> params = new Hashtable<>(); 
       params.put("apikey", Utilities.API_KEY); 
       params.put("secret", Utilities.SECRET_KEY); 
       params.put("email", username); 
       params.put("password",password); 
       //Adding parameters 
       //returning parameters 
       return params; 
      } 
     }; 
     //Creating a Request Queue 
     RequestQueue requestQueue = Volley.newRequestQueue(this); 
     //Adding request to the queue 
     requestQueue.add(stringRequest); 
    } 

feed.java

@Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_promotions_feed); 

     jsonResponse = new LoginPOJO(); 

     communityImage = (TextView) findViewById(R.id.communityImage); 

     communityImage.setOnClickListener((View.OnClickListener) this); 

     searchImage = (TextView) findViewById(R.id.searchImage); 

     searchImage.setOnClickListener((View.OnClickListener) this); 

     specialsImage = (TextView) findViewById(R.id.searchImage); 

     specialsImage.setOnClickListener(this); 

     calenderImage = (TextView) findViewById(R.id.calenderImage); 

     calenderImage.setOnClickListener(this); 

     profileImage = (TextView) findViewById(R.id.profileImage); 

     profileImage.setOnClickListener(this); 

     TextView response = (TextView) findViewById(R.id.response); 

     String data = LoginPOJO.getCode(); 

     response.setText(data); 

    } 
private void getPromotionsFeed(final String location) { 

     final ProgressDialog progressDialog = new ProgressDialog(PromotionsFeedActivity.this); 
     progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
     progressDialog.setMessage("Getting promotions feed..."); 
     progressDialog.setIndeterminate(true); 
     progressDialog.setCancelable(false); 
     progressDialog.show(); 
     String UPLOAD_URL = "http://xxxx-dev.elasticbeanstalk.com/api/v1/get_promotions_feed"; 
     final StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL, 
       new Response.Listener<String>() { 
        @Override 
        public void onResponse(String s) { 
         //Dismissing the progress dialog 
         progressDialog.dismiss(); 
         // Getting the final Json Object 
         JSONObject parentObject; 
         try { 
          parentObject = new JSONObject(s); 
         } catch (JSONException e) { 
          e.printStackTrace(); 
         } 
         //Showing toast message of the response 
         Log.i("TAG", "onResponse: " + s); 

        } 
       }, 
       new Response.ErrorListener() { 
        @Override 
        public void onErrorResponse(VolleyError volleyError) { 
         //Dismissing the progress dialog 
         progressDialog.dismiss(); 
         //Showing snackbar 
         Toast.makeText(PromotionsFeedActivity.this, "Connection Problem", Toast.LENGTH_SHORT).show(); 
        } 
       }) { 
      @Override 
      protected Map<String, String> getParams() throws AuthFailureError { 
       //Converting Bitmap to String 
       //Creating parameters 
       Map<String, String> params = new Hashtable<>(); 
       params.put("apikey", Utilities.API_KEY); 
       params.put("secret", Utilities.SECRET_KEY); 
       params.put("location","xxx"); 
       //Adding parameters 
       //returning parameters 
       return params; 
      } 
     }; 
     //Creating a Request Queue 
     RequestQueue requestQueue = Volley.newRequestQueue(this); 
     //Adding request to the queue 
     requestQueue.add(stringRequest); 
    } 

로그 캣

04-03 18:47:26.263 10750-10750/com.example.reception.farbinder_test I/TAG: onResponse: {"code":200,"status":"ok","message":"Logged in.","data":{"id":"Pg4yYHXIQK","firstName":"Arun","lastName":"","shortName":"Arun","email":"[email protected]","role":"owner","showInviteMessage":false,"verified":true,"zipCode":"07666","location":"Teaneck, NJ","geo":{"latitude":40.888461,"longitude":-74.012066,"zipcode":"07666","city":"Teaneck","state":"NJ","type":"geo"},"defaultCommunity":{"id":18313,"name":"Teaneck, NJ Community","city":"Teaneck","state":"NJ","latitude":40.888461,"longitude":-74.012066,"type":"community"},"businesses":[{"id":72,"name":"my bus","type":"business"}],"type":"user"},"meta":{"userVideoUrl":"https://d1e6yi6s3cx2ur.cloudfront.net/videos/0/_20160316_ios-user.m4v","businessVideoUrl":"https://d1e6yi6s3cx2ur.cloudfront.net/videos/0/_20160316_ios-business.m4v","promoVideoUrl":"https://d1e6yi6s3cx2ur.cloudfront.net/videos/0/_20160316_ios-user.m4v","searchVideoUrl":"https://d1e6yi6s3cx2ur.cloudfront.net/videos/0/_20160316_ios-user.m4v","faqUrl":"http://farbinder-dev.elasticbeanstalk.com/api/v1/faq","privacyUrl":"http://farbinder-dev.elasticbeanstalk.com/api/v1/privacy","termsUrl":"http://farbinder-dev.elasticbeanstalk.com/api/v1/terms","contactFormUrl":"http://farbinder-dev.elasticbeanstalk.com/api/v1/contact?u\u003d25fee27e9d18464eadbad0faa632a9b6e82787cc613ca64e","feedbackFormUrl":"http://farbinder-dev.elasticbeanstalk.com/api/v1/feedback?u\u003d25fee27e9d18464eadbad0faa632a9b6e82787cc613ca64e","type":"links"}} 
04-03 18:47:26.265 1518-1877/system_process W/InputMethodManagerService: Window already focused, ignoring focus gain of: [email protected] attribute=null, token = [email protected] 
04-03 18:47:26.326 1518-1660/system_process V/WindowManager: Adding window Window{11f00761 u0 com.example.reception.farbinder_test/com.example.reception.farbinder_test.PromotionsFeedActivity} at 4 of 10 (after Window{27eec5b0 u0 com.example.reception.farbinder_test/com.example.reception.farbinder_test.MainActivity EXITING}) 
04-03 18:47:26.330 1518-1880/system_process V/WindowManager: Adding window Window{1217747 u0 com.example.reception.farbinder_test/com.example.reception.farbinder_test.PromotionsFeedActivity} at 4 of 11 (before Window{11f00761 u0 com.example.reception.farbinder_test/com.example.reception.farbinder_test.PromotionsFeedActivity}) 
04-03 18:47:26.441 10750-10750/com.example.reception.farbinder_test E/RecyclerView: No adapter attached; skipping layout 
04-03 18:47:26.457 1162-1162/? W/SurfaceFlinger: couldn't log to binary event log: overflow. 
04-03 18:47:27.092 10750-10750/com.example.reception.farbinder_test I/TAG: onResponse: {"code":401,"status":"error","message":"User not logged in."} 

답변

0

당신은에 로그인 할 그런 다음 서비스가 관심있는 클래스에 성공적인 로그인을 브로드 캐스트하게하십시오.

+0

그래서 당신에 따르면 관심있는 수업에 대한 성공적인 로그인을 구문 분석해야합니다. 그러나 끝점의 나머지 부분은 이러한 자격 증명을 매개 변수로 사용하지 않습니다. 관심있는 수업에 어떻게 성공적으로 메시지를 보낼 수 있습니까? 샘플 코드로 설명해주십시오. @Gabe Sechan – Arun

+0

BroadcastReceivers를 조사하십시오. 또는 이벤트 버스. 또는 RxJava 관찰 가능. 또는 자신 만의 콜백 시스템을 롤업 한 바운드 서비스. 서비스에서 활동을 경고하는 수십 가지 방법이 있습니다. 몇 가지 조사를 해보십시오. –

+0

Ohh 좋아요. 감사합니다. @Gabe Sechan – Arun