com.android.volley.toolbox.Volley Java Examples

The following examples show how to use com.android.volley.toolbox.Volley. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MyApp.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate() {
	super.onCreate();
	singleInstance = this;
	iniIM();
	new Thread(new Runnable() {
		@Override
		public void run() {
			NotificationDataModel.applicationContextRef = new WeakReference<Context>(getApplicationContext());
			volleyRequestQueue = Volley.newRequestQueue(getApplicationContext());
			applicationContext = getApplicationContext();
			Fresco.initialize(singleInstance);
			MobclickAgent.openActivityDurationTrack(false);
		}
	}).start();
       iniMonitor();
       iniShareSDK();
	if(BuildConfig.DEBUG == true){
	Stetho.initialize(
			Stetho.newInitializerBuilder(this)
					.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
					.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
					.build());
}
}
 
Example #2
Source File: MainActivity.java    From android-advanced-light with MIT License 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv_image = (ImageView) this.findViewById(R.id.iv_image);
        bt_send = (Button) this.findViewById(R.id.bt_send);
        nv_image = (NetworkImageView) this.findViewById(R.id.nv_image);
        mQueue = Volley.newRequestQueue(getApplicationContext());
        bt_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                UseStringRequest();
                  UseJsonRequest();
//                UseImageRequest();
//                UseImageLoader();
//                UseNetworkImageView();
            }
        });
    }
 
Example #3
Source File: Act_NewHttpClient.java    From android_volley_examples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act__new_http_client);

    mTvResult = (TextView) findViewById(R.id.tv_result);

    Button btnSimpleRequest = (Button) findViewById(R.id.btn_simple_request);
    btnSimpleRequest.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Usually getting the request queue shall be in singleton like in {@see Act_SimpleRequest}
            // Current approach is used just for brevity
            RequestQueue queue = Volley
                    .newRequestQueue(Act_NewHttpClient.this,
                                     new ExtHttpClientStack(new DefaultHttpClient()));

            StringRequest myReq = new StringRequest(Method.GET,
                                                    "http://www.google.com/",
                                                    createMyReqSuccessListener(),
                                                    createMyReqErrorListener());

            queue.add(myReq);
        }
    });
}
 
Example #4
Source File: LoginFragment.java    From Anti-recall with GNU Affero General Public License v3.0 6 votes vote down vote up
private void sendMsg() {
    RequestQueue queue = Volley.newRequestQueue(getContext());
    StringRequest request = new StringRequest(Request.Method.POST, "http://ar.qsboy.com/j/applyCaptcha",
            response -> {
                Log.i(TAG, "sendMsg: " + response);
                captcha = response;
            },
            error -> Log.e(TAG, "sendMsg: " + error)) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> map = new HashMap<>();
            map.put("phone", phone);
            return map;
        }
    };
    queue.add(request);
}
 
Example #5
Source File: ScanService.java    From find3-android-scanner with MIT License 6 votes vote down vote up
@Override
public void onCreate() {
    // The service is being created
    Log.d(TAG, "creating new scan service");
    queue = Volley.newRequestQueue(this);
    // setup wifi
    wifi = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
    if (wifi.isWifiEnabled() == false) {
        wifi.setWifiEnabled(true);
    }
    // register wifi intent filter
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    registerReceiver(mWifiScanReceiver, intentFilter);

    try {
        // setup bluetooth
        Log.d(TAG, "setting up bluetooth");
        if (receiver == null) {
            receiver = new BluetoothBroadcastReceiver();
            registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }
}
 
Example #6
Source File: MainActivity.java    From cnode-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    queue = Volley.newRequestQueue(this);

    accountManager = AccountManager.get(this);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("");
    setSupportActionBar(toolbar);

    setupSwipingLayout();
    setupTopicsView();
    setupFilter();
}
 
Example #7
Source File: LocalSearch.java    From MapsSDK-Native with MIT License 6 votes vote down vote up
static void sendRequest(Context context, String query, GeoboundingBox bounds, Callback callback) {
    if (query == null || query.isEmpty()) {
        Toast.makeText(context, "Invalid query", Toast.LENGTH_LONG).show();
        return;
    }

    String boundsStr = String.format(Locale.ROOT,
        "%.6f,%.6f,%.6f,%.6f",
        bounds.getSouth(), bounds.getWest(), bounds.getNorth(), bounds.getEast());

    RequestQueue queue = Volley.newRequestQueue(context);
    queue.add(new StringRequest(
        Request.Method.GET,
        URL_ENDPOINT.replace("{query}", query).replace("{bounds}", boundsStr),
        (String response) -> {
            List<Poi> results = parse(response);
            if (results == null || results.isEmpty()) {
                callback.onFailure();
                return;
            }
            callback.onSuccess(results);
        },
        (VolleyError error) -> callback.onFailure()
    ));
}
 
Example #8
Source File: LyricsViewFragment.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
public void setCoverArt(String url, FadeInNetworkImageView coverView) {
    MainActivity mainActivity = (MainActivity) getActivity();
    if (mainActivity == null)
        return;
    mainActivity.findViewById(R.id.top_gradient).setVisibility(View.VISIBLE);
    mainActivity.findViewById(R.id.bottom_gradient).setVisibility(View.VISIBLE);
    if (coverView == null)
        coverView = mainActivity.findViewById(R.id.cover);
    if (url == null)
        url = "";
    if (mLyrics != null) {
        mLyrics.setCoverURL(url);
        coverView.setLyrics(mLyrics);
    }
    coverView.clearColorFilter();
    if (url.startsWith("/")) {
        coverView.setImageBitmap(BitmapFactory.decodeFile(url));
    } else {
        coverView.setImageUrl(url,
                new ImageLoader(Volley.newRequestQueue(mainActivity), CoverCache.instance()));
        if (!url.isEmpty() && mLyrics != null && mLyrics.getFlag() == Lyrics.POSITIVE_RESULT)
            DatabaseHelper.getInstance(getActivity()).updateCover(mLyrics.getArtist(), mLyrics.getTitle(), url);
    }
}
 
Example #9
Source File: MainActivity.java    From android-kubernetes-blockchain with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);

    // use tech fragment - initial layout
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.frame_layout, TechFragment.newInstance());
    transaction.commit();

    // request queue
    queue = Volley.newRequestQueue(this);

    // check if location is permitted
    if(ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        Log.d(TAG, "access fine location not yet granted");
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},1);
    }

    // initialize shared preferences - persistent data
    sharedPreferences = this.getSharedPreferences("shared_preferences_fitcoin", Context.MODE_PRIVATE);

    // Check if user is already enrolled
    if (sharedPreferences.contains("BlockchainUserId")) {
        Log.d(TAG, "User already registered.");
    } else {
            // register the user
            registerUser();
    }
}
 
Example #10
Source File: QuoteView.java    From AndroidDemoProjects with Apache License 2.0 5 votes vote down vote up
private void generateQuote() {
	GsonRequest<Quote> request = new GsonRequest<Quote>(
			Request.Method.GET,
			getResources().getString( R.string.random_quote_url_json ),
			Quote.class,
			onSuccessListener(),
			onErrorListener() );

	Volley.newRequestQueue( getContext() ).add(request);
}
 
Example #11
Source File: AppController.java    From ImageSliderWithSwipes with Apache License 2.0 5 votes vote down vote up
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }
 
    return mRequestQueue;
}
 
Example #12
Source File: VolleySingleton.java    From LuxVilla with Apache License 2.0 5 votes vote down vote up
public RequestQueue getRequestQueue() {
    if (mrequestQueue == null) {

        mrequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
    }
    return mrequestQueue;
}
 
Example #13
Source File: RssListAdapter.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
public RssListAdapter(Context context, List<Item> items) {
    super(context, 0, items);
    mItems = items;
    mInflator = (LayoutInflater) getContext().getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);
    mQueue = Volley.newRequestQueue(context);
    mImageLoader = new ImageLoader(mQueue, new LruImageCache());
}
 
Example #14
Source File: NetworkService.java    From CoolClock with GNU General Public License v3.0 5 votes vote down vote up
private RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue =
                Volley.newRequestQueue(ClockApplication.getContext());
    }
    return mRequestQueue;
}
 
Example #15
Source File: BaseVolleyApi.java    From Android_framework with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static RequestQueue getRequestQueue() {
    if (requestQueue == null) {
        synchronized (BaseVolleyApi.class){
            if (requestQueue == null)
                requestQueue = Volley.newRequestQueue(RootApplication.getInstance());
        }
    }
    return requestQueue;
}
 
Example #16
Source File: MainActivity.java    From custom-auth-samples with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param kakaoAccessToken Access token retrieved after successful Kakao Login
 * @return Task object that will call validation server and retrieve firebase token
 */
private Task<String> getFirebaseJwt(final String kakaoAccessToken) {
    final TaskCompletionSource<String> source = new TaskCompletionSource<>();

    RequestQueue queue = Volley.newRequestQueue(this);
    String url = getResources().getString(R.string.validation_server_domain) + "/verifyToken";
    HashMap<String, String> validationObject = new HashMap<>();
    validationObject.put("token", kakaoAccessToken);

    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(validationObject), new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                String firebaseToken = response.getString("firebase_token");
                source.setResult(firebaseToken);
            } catch (Exception e) {
                source.setException(e);
            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, error.toString());
            source.setException(error);
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("token", kakaoAccessToken);
            return params;
        }
    };

    queue.add(request);
    return source.getTask();
}
 
Example #17
Source File: MenusAdapter.java    From elemeimitate with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	final ViewHolder viewHolder ;
	if(convertView == null){
		convertView = inflater.inflate(R.layout.item_menu_content, parent, false);
		viewHolder = new ViewHolder();
		viewHolder.iv_image = (ImageView)convertView.findViewById(R.id.item_menu_content_img);
		viewHolder.tv_menusName = (TextView)convertView.findViewById(R.id.item_menu_content_title);
		viewHolder.tv_price = (TextView)convertView.findViewById(R.id.item_menu_content_price);
		
		convertView.setTag(viewHolder);
	}else{
		viewHolder = (ViewHolder)convertView.getTag();
	}

	//创建一个RequestQueue对象
	RequestQueue requestQueue = Volley.newRequestQueue(context);
	     	
    //创建ImageRequest对象
	ImageRequest imageRequest = new ImageRequest(
			Constant.URL_WEB_SERVER+datas.get(position).get("menusImagePath").toString(),//url
	    	new Response.Listener<Bitmap>() {//监听器Listener
				@Override
	    		public void onResponse(Bitmap response) {
	    			viewHolder.iv_image.setImageBitmap(response);
	    		}
	    		//参数3、4表示图片宽高,Bitmap.Config.ARGB_8888表示图片每个像素占据4个字节大小
	    	}, 0, 0, Config.ARGB_8888, new Response.ErrorListener() {//图片加载请求失败的回调Listener
	    			@Override
	    			public void onErrorResponse(VolleyError error) {
	    				viewHolder.iv_image.setImageResource(R.drawable.ic_normal_pic);
	    			}
	    	});
	//将ImageRequest加载到Queue
	 requestQueue.add(imageRequest);
	    
	viewHolder.tv_menusName.setText(datas.get(position).get("menuName").toString());
	viewHolder.tv_price.setText("¥"+datas.get(position).get("total_price").toString());
	return convertView;
}
 
Example #18
Source File: KCommands.java    From kboard with GNU General Public License v3.0 5 votes vote down vote up
public void curl(int n, String parameter) {
        // Instantiate the RequestQueue.
        RequestQueue queue = Volley.newRequestQueue(mIme);
        final int repeat = n;

        // Request a string response from the provided URL.
        StringRequest stringRequest = new StringRequest(Request.Method.GET, parameter,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        i(repeat, response);
                    }


                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        }) {
            @Override
            public Map<String, String> getHeaders(){
                Map<String, String> headers = new HashMap<>();
                headers.put("User-agent", "curl");
                headers.put("Accept", "text/plain");
                return headers;
            }
        };

// Add the request to the RequestQueue.
        queue.add(stringRequest);
    }
 
Example #19
Source File: RequestManager.java    From android-common-utils with Apache License 2.0 5 votes vote down vote up
public static void init(Context context) {
	mRequestQueue = Volley.newRequestQueue(context);

	int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE))
			.getMemoryClass();
	// Use 1/8th of the available memory for this memory cache.
	int cacheSize = 1024 * 1024 * memClass / 8;
	mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(cacheSize));
}
 
Example #20
Source File: VolleyResourcesSingleton.java    From m2x-android with MIT License 5 votes vote down vote up
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        // getApplicationContext() is key, it keeps you from leaking the
        // Activity or BroadcastReceiver if someone passes one in.
        mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
    }
    return mRequestQueue;
}
 
Example #21
Source File: Huaban.java    From Presentation with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    mInstance = Huaban.this;

    mGson = new Gson();
    mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(getApplicationContext()));

    mDatabaseHelper = new DatabaseHelper(getApplicationContext());
    mPresentationsManager = new PstManager(getApplicationContext());
}
 
Example #22
Source File: VolleyClient.java    From EasyPay with Apache License 2.0 5 votes vote down vote up
@Override
public void get(PayParams payParams, final CallBack c) {
    RequestQueue queue = Volley.newRequestQueue(payParams.getActivity());
    String baseUrl = payParams.getApiUrl();
    StringBuffer sburl = new StringBuffer();
    sburl.append(baseUrl)
            .append("?")
            .append("pay_way=").append(payParams.getPayWay())
            .append("&")
            .append("price=").append(payParams.getGoodsPrice())
            .append("&")
            .append("goods_name=").append(payParams.getGoodsName())
            .append("&")
            .append("goods_introduction=").append(payParams.getGoodsIntroduction());
    StringRequest request = new StringRequest(Request.Method.GET, sburl.toString(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    c.onSuccess(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            c.onFailure();
        }
    });
    queue.add(request);
}
 
Example #23
Source File: VolleyClient.java    From EasyPay with Apache License 2.0 5 votes vote down vote up
@Override
public void post(final PayParams payParams, final CallBack c) {
    RequestQueue queue = Volley.newRequestQueue(payParams.getActivity());
    StringRequest request = new StringRequest(Request.Method.POST, payParams.getApiUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    c.onSuccess(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            c.onFailure();
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("pay_way", payParams.getPayWay().toString());
            params.put("price", String.valueOf(payParams.getGoodsPrice()));
            params.put("goods_name", payParams.getGoodsName());
            params.put("goods_introduction", payParams.getGoodsIntroduction());

            return params;
        }
    };

    queue.add(request);
}
 
Example #24
Source File: MyVolley.java    From Android-SDK with MIT License 5 votes vote down vote up
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null)
        mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());

    mRequestQueue.getCache().clear();

    return mRequestQueue;
}
 
Example #25
Source File: GosScheduleSiteTool.java    From Gizwits-SmartBuld_Android with MIT License 5 votes vote down vote up
/**
 * @param context
 */
public GosScheduleSiteTool(Context context, GizWifiDevice device, String token) {
	super();
	this.device = device;
	this.token = token;
	mRequestQueue = Volley.newRequestQueue(context.getApplicationContext());
	APPID = GosDeploy.setAppID();

}
 
Example #26
Source File: GutenbergApplication.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
/**
 * @return The instance of {@link RequestQueue}.
 */
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(this);
        mRequestQueue.start();
    }
    return mRequestQueue;
}
 
Example #27
Source File: MainActivity.java    From android-https-volley with Apache License 2.0 5 votes vote down vote up
private void createHttpRequestUsedToVolley() {
    VolleyListener listener = new VolleyListener();
    RequestQueue queue = Volley.newRequestQueue(this, new SslHttpStack(new SslHttpClient(getBaseContext(), 44400)));
    StringRequest request = new StringRequest(
            Request.Method.GET,
            REQUEST_URL,
            listener,
            listener);
    queue.add(request);
}
 
Example #28
Source File: LoginFragment.java    From Anti-recall with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean verifyCaptcha(String captcha) {
    RequestQueue queue = Volley.newRequestQueue(getContext());
    RequestFuture future = RequestFuture.newFuture();
    StringRequest request = new StringRequest(Request.Method.POST,
            "http://ar.qsboy.com/j/verifyCaptcha", future, future) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> map = new HashMap<>();
            map.put("phone", phone);
            map.put("captcha", captcha);
            return map;
        }
    };

    queue.add(request);

    try {
        String s = (String) future.get(5, TimeUnit.SECONDS);
        boolean isValid = s != null && s.length() > 0;
        if (isValid) {
            Gson gson = new Gson();
            gson.fromJson(s, App.User.class);
        }
        return isValid;
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        e.printStackTrace();
        return false;
    }
}
 
Example #29
Source File: MySingleton.java    From Netease with GNU General Public License v3.0 5 votes vote down vote up
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        // getApplicationContext() is key, it keeps you from leaking the
        // Activity or BroadcastReceiver if someone passes one in.
        mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext(), null, 30 * 1024 * 1024);
    }
    return mRequestQueue;
}
 
Example #30
Source File: MainActivity.java    From nearbydemo with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	boolean first = getSharedPreferences("userinfo", Context.MODE_PRIVATE).getBoolean("first", false);

	if (!first) {
		Intent intent = new Intent(this, LoginActivity.class);
		startActivity(intent);
	}

	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	reqQueue = Volley.newRequestQueue(this);
	imageLoader = new ImageLoader(reqQueue, new BitmapLruCache());
	
	
	//百度地图定位
	mLocationClient = new LocationClient(getApplicationContext());//是否有问题??
	mMyLocationListener = new MyLocationListener();
	mLocationClient.registerLocationListener(mMyLocationListener);
	
	
	LocationClientOption option = new LocationClientOption();
	option.setLocationMode(LocationMode.Hight_Accuracy);// 设置定位模式
	option.setCoorType("bd09ll");// 返回的定位结果是百度经纬度,默认值gcj02
	option.setIsNeedAddress(true);// 返回的定位结果包含地址信息
	option.setNeedDeviceDirect(true);// 返回的定位结果包含手机机头的方向
	mLocationClient.setLocOption(option);

}