当前位置: 首页>>代码示例>>Java>>正文


Java JsonObjectRequest.setRetryPolicy方法代码示例

本文整理汇总了Java中com.android.volley.toolbox.JsonObjectRequest.setRetryPolicy方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObjectRequest.setRetryPolicy方法的具体用法?Java JsonObjectRequest.setRetryPolicy怎么用?Java JsonObjectRequest.setRetryPolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.volley.toolbox.JsonObjectRequest的用法示例。


在下文中一共展示了JsonObjectRequest.setRetryPolicy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getArticles

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
public void getArticles(String source, final ResultCallback resultCallback){
    JsonObjectRequest request=new JsonObjectRequest(Request.Method.GET,
            "https://newsapi.org/v1/articles?source=" + source + "&apiKey=7da1d69096ce497d805cc484fb90e8ee",
            null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    List<Article> articles=new ArrayList<>();
                    try {
                        JSONArray articlesJsonArray=response.getJSONArray("articles");
                        for (int i = 0; i < articlesJsonArray.length(); i++) {
                            JSONObject articlesJSONObject=articlesJsonArray.getJSONObject(i);
                            Article article=new Article();
                            article.setAuthor(articlesJSONObject.getString("author"));
                            article.setTitle(articlesJSONObject.getString("title"));
                            article.setDescription(articlesJSONObject.getString("description"));
                            article.setUrl(articlesJSONObject.getString("url"));
                            article.setImageUrl(articlesJSONObject.getString("urlToImage"));
                            article.setDate(articlesJSONObject.getString("publishedAt"));
                            articles.add(article);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    resultCallback.onArticlesReceived(articles);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            resultCallback.onError("اختلال در دریافت اطلاعات");
        }
    });
    //send
    request.setRetryPolicy(new DefaultRetryPolicy(20000,DefaultRetryPolicy.DEFAULT_MAX_RETRIES,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    RequestQueueContainer.getInstance(context).add(request);
}
 
开发者ID:saeedsh92,项目名称:AndroidExpert-AndroidBasicConcepts,代码行数:38,代码来源:NewsApiService.java

示例2: updatePlayer

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
public void updatePlayer() {
    updateCurrentShow();

    nowPlaying = DataModel.getNowPlaying(getActivity());

    String nowPlayingArtist = nowPlaying.get("artist");
    String nowPlayingSong = nowPlaying.get("song");

    nowPlayingTextView.setText(nowPlayingArtist + "\n" + nowPlayingSong);

    String url = "http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=" + getString(R.string.LASTFM_API_KEY) + "&artist=" + nowPlayingArtist + "&track=" + nowPlayingSong + "&autocorrect&format=json";
    url = url.replaceAll(" ", "%20");

    JsonObjectRequest objectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject jsonObject) {
            updateImageWithResponse(jsonObject);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            displayCurrentShowImage();
        }
    });
    objectRequest.setRetryPolicy(DataModel.getRetryPolicy());

    VolleySingleton.getInstance(getActivity()).getRequestQueue().add(objectRequest);

    // Updates notification sooner, before image is retrieved, but means notification is updated twice
    displayNotification(previousNotificationLargeIcon);
}
 
开发者ID:dylanmaryk,项目名称:InsanityRadio-Android,代码行数:32,代码来源:FragmentNowPlaying.java

示例3: sendRequest

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
private void sendRequest(String url) {
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(url, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            loadToast.success();
            list = parseResponse(response);
            adapter.refresh(list);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            loadToast.error();
            NetworkResponse networkResponse = error.networkResponse;
            if (networkResponse != null) {
                if (networkResponse.statusCode == 401) {
                    Toast.makeText(Leaderboard.this, "INVALID ACCESS", Toast.LENGTH_SHORT).show();
                }
                if (error instanceof TimeoutError) {
                    Toast.makeText(Leaderboard.this, "TIME OUT ERROR", Toast.LENGTH_SHORT).show();
                } else if (error instanceof ServerError) {
                    Toast.makeText(Leaderboard.this, "SERVER ERROR", Toast.LENGTH_SHORT).show();
                }
                error.printStackTrace();
            }
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> map = new HashMap<>();
            map.put("Authorization", "bearer " + personalData.getToken());
            return map;
        }
    };
    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, 5, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    MySingleton.getInstance(MyApplication.getAppContext()).addToRequestQueue(jsonObjectRequest);
}
 
开发者ID:appteam-nith,项目名称:festnimbus,代码行数:37,代码来源:Leaderboard.java

示例4: callGraphAPI

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
private void callGraphAPI() {
    Log.d(TAG, "Starting volley request to graph");

    /* Make sure we have a token to send to graph */
    if (authResult.getAccessToken() == null) {return;}

    RequestQueue queue = Volley.newRequestQueue(this);
    JSONObject parameters = new JSONObject();

    try {
        parameters.put("key", "value");
    } catch (Exception e) {
        Log.d(TAG, "Failed to put parameters: " + e.toString());
    }
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, MSGRAPH_URL,
            parameters,new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            /* Successfully called graph, process data and send to UI */
            Log.d(TAG, "Response: " + response.toString());

            updateGraphUI(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d(TAG, "Error: " + error.toString());
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> headers = new HashMap<>();
            headers.put("Authorization", "Bearer " + authResult.getAccessToken());
            return headers;
        }
    };

    Log.d(TAG, "Adding HTTP GET to Queue, Request: " + request.toString());

    request.setRetryPolicy(new DefaultRetryPolicy(
            3000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    queue.add(request);
}
 
开发者ID:Azure-Samples,项目名称:active-directory-android-native-v2,代码行数:46,代码来源:MainActivity.java

示例5: deleteListing

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
public void deleteListing(int product_id) {

        getView().showDialog();

        String url = QuireAPI.BASE_URL + QuireAPI.USERS_ENDPOINT + "/" + Quire.userID + "/products/" + product_id;

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.DELETE, url,
                null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {

                getView().hideDialog();

                Log.d(LOG_TAG, "Delete item response: " + response);

                try {
                    boolean success = response.getBoolean("success");
                    if (success) {
                        getView().showSuccessDialog();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                getView().hideDialog();
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put("Authorization", Quire.access_token);
                return headers;
            }

        };

        jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
                15000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        RequestQueue queue = Volley.newRequestQueue(mContext);
        queue.add(jsonObjectRequest);
    }
 
开发者ID:narenkukreja,项目名称:quire,代码行数:49,代码来源:SingleUserListingPresenter.java

示例6: persistChatToAPI

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
private void persistChatToAPI(final Integer productId, final String chatUrl) throws JSONException {

        mProgressDialog = ProgressDialog.show(mContext, "", mContext.getString(R.string.all_dialog_loading), true);

        // {host}/me/skipped_products
        String url = QuireAPI.BASE_URL + QuireAPI.ME_ENDPOINT + QuireAPI.CHAT_ENDPOINT;

        JSONObject productObj = new JSONObject();
        productObj.put("product_id", productId);
        productObj.put("url", chatUrl);

        JSONObject chatObject = new JSONObject();
        chatObject.put("chat", productObj);

        Log.d(LOG_TAG, chatObject.toString());

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
                url,
                chatObject,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        mProgressDialog.dismiss();
                        Intent intent = new Intent(mContext, GroupChannelActivity.class);
                        intent.putExtra("channel_url", chatUrl);
                        mContext.startActivity(intent);
                        Activity activity = (Activity) mContext;
                        activity.overridePendingTransition(R.anim.left_out, R.anim.right_in);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                mProgressDialog.dismiss();
                Toasty.error(mContext, "chat creation error! :( - " + error, Toast.LENGTH_LONG).show();
            }
        }
        ) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put("Content-Type", "application/json; charset=utf-8");
                headers.put("Authorization", Quire.access_token);

                return headers;
            }
        };

        jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
                15000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        RequestQueue queue = Volley.newRequestQueue(mContext);
        queue.add(jsonObjectRequest);
    }
 
开发者ID:narenkukreja,项目名称:quire,代码行数:56,代码来源:NearbyProductsAdapter.java

示例7: hideProduct

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
private void hideProduct(int id) throws JSONException {

        // {host}/me/skipped_products
        String url = QuireAPI.BASE_URL + "/me" + QuireAPI.SKIPPED_PRODUCTS_ENPOINT;

        JSONObject productObj = new JSONObject();
        productObj.put("product_id", id);

        JSONObject skippedObj = new JSONObject();
        skippedObj.put("skipped_product", productObj);

        Log.d(LOG_TAG, skippedObj.toString());

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
                url, skippedObj, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                Log.d(LOG_TAG, "Skipped res: " + response.toString());
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d(LOG_TAG, "Skipped res: " + error.toString());
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put("Content-Type", "application/json; charset=utf-8");
                headers.put("Authorization", Quire.access_token);
                return headers;
            }
        };

        jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
                15000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        RequestQueue queue = Volley.newRequestQueue(mContext);
        queue.add(jsonObjectRequest);
    }
 
开发者ID:narenkukreja,项目名称:quire,代码行数:43,代码来源:NearbyProductsAdapter.java

示例8: updateUserLocation

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
private void updateUserLocation(String userLat, String userLng) throws JSONException {

        // {host}/users/{user_id}/
        String url = QuireAPI.BASE_URL + QuireAPI.USERS_ENDPOINT + "/" + Quire.userID;

        JSONObject params = new JSONObject();
        params.put("last_location", "POINT(" + userLng + " " + userLat + ")");

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.PUT,
                url, params, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {

                Log.d(LOG_TAG, "location update success response: " + response.toString());

                mViewPager = (ViewPager) findViewById(R.id.view_pager);
                mAdapter = new ViewPagerAdapter(getSupportFragmentManager());
                mViewPager.setAdapter(mAdapter);

                mViewPager.setCurrentItem(0);
                mViewPager.setOffscreenPageLimit(2);

                final View touchView = mViewPager;
                touchView.setOnTouchListener(new View.OnTouchListener()
                {
                    @Override
                    public boolean onTouch(View v, MotionEvent event)
                    {
                        return true;
                    }
                });

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d(LOG_TAG, "update location error: " + error.toString());
            }
        }){

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put("Content-Type", "application/json; charset=utf-8");
                headers.put("Authorization", Quire.access_token);
                return headers;
            }

        };

        jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
                15000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
        queue.add(jsonObjectRequest);

        connect();

    }
 
开发者ID:narenkukreja,项目名称:quire,代码行数:62,代码来源:NearbyProductsActivity.java

示例9: persistChatToAPI

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
public void persistChatToAPI(Integer productId, final String chatUrl) throws JSONException {

        getView().showDialog();

        // {host}/me/skipped_products
        String url = QuireAPI.BASE_URL + QuireAPI.ME_ENDPOINT + QuireAPI.CHAT_ENDPOINT;

        JSONObject productObj = new JSONObject();
        productObj.put("product_id", productId);
        productObj.put("url", chatUrl);

        JSONObject chatObject = new JSONObject();
        chatObject.put("chat", productObj);

        Log.d(LOG_TAG, chatObject.toString());

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
                url,
                chatObject,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {

                        getView().hideDialog();
                        getView().startChatActivity(chatUrl);

                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toasty.error(mContext, "chat creation error! :( - " + error, Toast.LENGTH_LONG).show();
            }
        }
        ) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<>();
                headers.put("Content-Type", "application/json; charset=utf-8");
                headers.put("Authorization", Quire.access_token);

                return headers;
            }
        };

        jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(
                15000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        RequestQueue queue = Volley.newRequestQueue(mContext);
        queue.add(jsonObjectRequest);
    }
 
开发者ID:narenkukreja,项目名称:quire,代码行数:53,代码来源:ViewSingleListingPresenter.java

示例10: getProductData

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
private void getProductData(String ProductsUrl)
{
    progressBar.setVisibility(View.VISIBLE);

    final int pageNumber = pageIndex;

    JsonObjectRequest mJsonObjectRequest = new JsonObjectRequest(Request.Method.GET, ProductsUrl, new Response.Listener<JSONObject>()
    {
        @Override
        public void onResponse(JSONObject response)
        {
            if(response.length() >= 1)
            {
                mainActPresenter.setAllData(response,pageIndex);

            }
            else
            {
                if(pageNumber != 0)
                {
                    pageIndex = pageNumber - 1;
                }
            }

            if(progressBar != null)
            {
                progressBar.setVisibility(View.GONE);
            }
        }
    }, new Response.ErrorListener()
    {
        @Override
        public void onErrorResponse(VolleyError error)
        {

            if(progressBar != null)
            {
                progressBar.setVisibility(View.GONE);
            }
        }
    });
    mJsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(30000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    MySingleton.getInstance(MainActivity.this).addToRequestQueue(mJsonObjectRequest);

    /*
     *  Above MySingleton is used to Create a Instance Object only one time
     *  which is used to maintain Queue of Request Because Request If no Resonse came
     *  Request is made again to server within 30 second if 20 second exceeds
     *  it will show the timeout.
     */
}
 
开发者ID:yash786agg,项目名称:RecyclerView-Pagination-using-MVP,代码行数:54,代码来源:MainActivity.java

示例11: updateLocationDB

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
public void updateLocationDB() {
    Gson gson = new Gson();
    String json = sharedPreferencesProfileInformation.getString("currentUser", "");
    currentUser = gson.fromJson(json, User.class);
    CustomLocation customLocation = new CustomLocation(mLatitude,currentUser.getId(),mLongitude);
    String postUser = gson.toJson(customLocation, CustomLocation.class);

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
            Request.Method.POST,
            AppConfig.MAP_URL_SEND,
            postUser,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject jsonObject) {
                    try {
                        Log.d("RESPONSE", jsonObject.toString());
                        //TODO parse response
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                }
            }
    ){
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            super.getHeaders();
            HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Content-Type", "application/json");
            headers.put("charset", "utf-8");
            headers.put("abc",currentUser.getAuthToken());
            return headers;
        }
    };

    int socketTimeout = 10000;
    RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
    jsonObjectRequest.setRetryPolicy(policy);
    MySingleton.getInstance(MainMenuActivity.this).addToRequestQueue(jsonObjectRequest);
}
 
开发者ID:Amay-Mishra,项目名称:Trackr,代码行数:46,代码来源:MainMenuActivity.java

示例12: doInBackground

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
@Override
protected String doInBackground(Void... params) {
    Log.d("tagged", "doInBackground: ");
    JsonObjectRequest jsonObjectRequest= new JsonObjectRequest(Request.Method.GET, jsonURL, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                ArrayList<NewsPOGO> newsArray =new ArrayList<>();
                Log.d("tagged", "onResponse: "+response.toString());
                resp=response.toString();
                JSONArray jsonArray=response.getJSONArray("objects");
                for(int i=0;i<jsonArray.length();i++)
                {
                    JSONObject jsonObject= jsonArray.getJSONObject(i);

                    newsPOGO=new NewsPOGO();
                    newsPOGO.body=jsonObject.getString("body");
                    newsPOGO.category=jsonObject.getString("category");
                    newsPOGO.content_type=jsonObject.getString("content_type");
                    newsPOGO.id=jsonObject.getInt("id");
                    newsPOGO.image=jsonObject.getString("image");
                    newsPOGO.likes=jsonObject.getInt("likes");
                    newsPOGO.link=jsonObject.getString("link");
                    newsPOGO.timestamp=jsonObject.getString("timestamp");
                    newsPOGO.title=jsonObject.getString("title");
                    newsPOGO.types=jsonObject.getString("types");
                    newsPOGO.user_id=jsonObject.getInt("user_id");
                    newsArray.add(newsPOGO);

                }

                if(newsArray.size()!=NewsPOGO.newsArray.size())
                {
                    NewsPOGO.newsArray.clear();
                    NewsPOGO.newsArray=newsArray;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            resp=error.toString();
            Log.d("tagged", "onResponse: "+error.toString());
            //name.setText("ERROR...");
            Toast.makeText(context, "Error Occured", Toast.LENGTH_SHORT).show();
        }
    });


    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(5000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    MySingleton.getMyInstance(context).addToReqQue(jsonObjectRequest);

    return resp;
}
 
开发者ID:goutham-kalikrishna,项目名称:ShotsNewsApp,代码行数:59,代码来源:GetNewsAsync.java

示例13: verifyOTP

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
private void verifyOTP(String verCode) {

        showProgress(true);

        String urlString = VERIFY_CODE_URL + "?api_key=" + TWILIO_API_KEY +
                "&phone_number=" + userPhone +
                "&country_code=" + "91" +
                "&verification_code=" + verCode;

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
                urlString, null,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d(TAG, "Response: " + response.toString());

                        try {
                            boolean success = response.getBoolean("success");
                            if (success) {
                                Toast.makeText(getApplicationContext(), R.string.otp_verification_success_message,
                                        Toast.LENGTH_SHORT).show();
                                if (callingActivity != null && callingActivity.equals("SettingsActivity")) {
                                    // update the settings preference
                                    SharedPreferences settingsPref = PreferenceManager
                                            .getDefaultSharedPreferences(getApplicationContext());
                                    SharedPreferences.Editor settingsEditor = settingsPref.edit();
                                    settingsEditor.putString("prefPhone", userPhone);
                                    settingsEditor.commit();
                                }
                                Intent intent = new Intent();
                                intent.putExtra("NEW_PHONE", userPhone);
                                setResult(RESULT_OK, intent);
                                finish();
                            } else {
                                showProgress(false);
                                Toast.makeText(getApplicationContext(), R.string.otp_verification_error_message,
                                        Toast.LENGTH_SHORT).show();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                            Log.d(TAG, "JSON Error: " + e.getMessage());
                            showProgress(false);
                            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                        }

                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error in " + TAG + " : " + error.getMessage());
                if (error instanceof TimeoutError)
                    VolleyLog.d(TAG, "Error in " + TAG + " : " + "Timeout Error");
                showProgress(false);
                Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });

        //Set a retry policy in case of SocketTimeout & ConnectionTimeout Exceptions.
        //Volley does retry for you if you have specified the policy.
        jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(SOCKET_TIMEOUT_MS,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(jsonObjReq);
    }
 
开发者ID:DevipriyaSarkar,项目名称:Damsel-In-Distress,代码行数:70,代码来源:OTPVerificationActivity.java

示例14: verifyPhone

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
private void verifyPhone(final String userPhone) {

        String urlString = START_PHONE_VERIFICATION_URL;

        Map<String, String> startParams = new HashMap<>();
        startParams.put("api_key", TWILIO_API_KEY);
        startParams.put("via", "sms");
        startParams.put("phone_number", userPhone);
        startParams.put("country_code", "91");
        startParams.put("locale", "en");

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                urlString, new JSONObject(startParams),
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d(TAG, "Response: " + response.toString());

                        try {
                            boolean success = response.getBoolean("success");
                            if (success) {
                                showProgress(false);
                                Intent intent = new Intent(getApplicationContext(), OTPVerificationActivity.class);
                                intent.putExtra("USER_PHONE", userPhone);
                                startActivityForResult(intent, REQUEST_VERIFICATION);
                            } else {
                                showProgress(false);
                                mPhoneView.setError(getString(R.string.error_incorrect_credentials));
                                mPhoneView.requestFocus();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                            Log.d(TAG, "JSON Error: " + e.getMessage());
                            showProgress(false);
                            Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                        }

                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d(TAG, "Error in " + TAG + " : " + error.getMessage());
                showProgress(false);
                if (error instanceof TimeoutError)
                    VolleyLog.d(TAG, "Error in " + TAG + " : " + "Timeout Error");
                Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });

        //Set a retry policy in case of SocketTimeout & ConnectionTimeout Exceptions.
        //Volley does retry for you if you have specified the policy.
        jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(SOCKET_TIMEOUT_MS,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(jsonObjReq);
    }
 
开发者ID:DevipriyaSarkar,项目名称:Damsel-In-Distress,代码行数:62,代码来源:RegisterActivity.java

示例15: verifyPhone

import com.android.volley.toolbox.JsonObjectRequest; //导入方法依赖的package包/类
private static void verifyPhone(final String userPhone, final Preference preference) {

        showPDialog();

        String urlString = START_PHONE_VERIFICATION_URL;

        Map<String, String> startParams = new HashMap<>();
        startParams.put("api_key", TWILIO_API_KEY);
        startParams.put("via", "sms");
        startParams.put("phone_number", userPhone);
        startParams.put("country_code", "91");
        startParams.put("locale", "en");

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                urlString, new JSONObject(startParams),
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        Log.d("SettingsActivity", "Response: " + response.toString());

                        try {
                            boolean success = response.getBoolean("success");
                            if (success) {
                                hidePDialog();
                                Intent intent = new Intent(preference.getContext(), OTPVerificationActivity.class);
                                Bundle bundle = new Bundle();
                                bundle.putString("USER_PHONE", userPhone);
                                bundle.putString("CALLING_ACTIVITY", "SettingsActivity");
                                intent.putExtras(bundle);
                                Activity activity = (Activity) preference.getContext();
                                activity.startActivityForResult(intent, REQUEST_VERIFICATION);
                            } else {
                                hidePDialog();
                                Toast.makeText(preference.getContext(), R.string.phone_incorrect_error, Toast.LENGTH_SHORT).show();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                            Log.d("SettingsActivity", "JSON Error: " + e.getMessage());
                            hidePDialog();
                            Toast.makeText(preference.getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                        }

                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("SettingsActivity", "Error in " + "SettingsActivity" + " : " + error.getMessage());
                if (error instanceof TimeoutError)
                    VolleyLog.d("SettingsActivity", "Timeout Error");
                hidePDialog();
                Toast.makeText(preference.getContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });

        //Set a retry policy in case of SocketTimeout & ConnectionTimeout Exceptions.
        //Volley does retry for you if you have specified the policy.
        jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(SOCKET_TIMEOUT_MS,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(jsonObjReq);
    }
 
开发者ID:DevipriyaSarkar,项目名称:Damsel-In-Distress,代码行数:67,代码来源:SettingsActivity.java


注:本文中的com.android.volley.toolbox.JsonObjectRequest.setRetryPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。