Java Code Examples for com.android.volley.toolbox.Volley

The following examples show how to use com.android.volley.toolbox.Volley. These examples are extracted from open source projects. 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 Project: MapsSDK-Native   Source File: LocalSearch.java    License: 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 2
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 3
Source Project: cnode-android   Source File: MainActivity.java    License: 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 4
Source Project: find3-android-scanner   Source File: ScanService.java    License: 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 5
Source Project: android-advanced-light   Source File: MainActivity.java    License: 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 6
Source Project: nono-android   Source File: MyApp.java    License: 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 7
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 8
Source Project: android_volley_examples   Source File: Act_NewHttpClient.java    License: 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 9
Source Project: renrenpay-android   Source File: ApiBll.java    License: Apache License 2.0 5 votes vote down vote up
public static ApiBll getInstance() {
    if (mApiBll == null) {
        mApiBll = new ApiBll();
        mApiBll.mQueue = Volley.newRequestQueue(AppContext.getInstance());
    }
    return mApiBll;
}
 
Example 10
Source Project: ExRecyclerView   Source File: WaterFallApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    // 不必为每一次HTTP请求都创建一个RequestQueue对象,推荐在application中初始化
    requestQueue = Volley.newRequestQueue(this);
    // 初始化fresco库
    Fresco.initialize(this);
}
 
Example 11
Source Project: jus   Source File: VolleyFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void standardQueueStringRequest(View v) {
	final TextView mTextView = (TextView) v.findViewById(R.id.tv_string_request);

	// StringRequest with VOLLEY with Standard RequestQueue
	// Instantiate the RequestQueue.
	requestQueue = Volley.newRequestQueue(v.getContext());
	String url = "http://www.google.com";

	// Request a string response from the provided URL.
	StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
			new Response.Listener<String>() {
				@Override
				public void onResponse(String response) {
					// Display the first 500 characters of the response string.
					mTextView.setText("Response is: " + response.substring(0, 500));
				}
			}, new Response.ErrorListener() {
		@Override
		public void onErrorResponse(VolleyError error) {
			mTextView.setText("That didn't work!");
		}
	});

	stringRequest.setTag(TAG);
	// Add the request to the RequestQueue.
	requestQueue.add(stringRequest);
}
 
Example 12
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mBroadcastManager = LocalBroadcastManager.getInstance(getContext());

    mImagesQueue = Volley.newRequestQueue(getActivity());
    mServiceIntent = new Intent(getActivity(), IntervalometerService.class);

    mTimelapseData = ((TimelapseApplication) getActivity().getApplication()).getTimelapseData();
    mSettings = mTimelapseData.getSettings();
    mApiRequestsList = mTimelapseData.getApiRequestsList();
}
 
Example 13
Source Project: kboard   Source File: KCommands.java    License: 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 14
Source Project: Study_Android_Demo   Source File: MyApp.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    //初始化RequestQueue
    queue = Volley.newRequestQueue(this);

}
 
Example 15
Source Project: volley   Source File: HttpTools.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 发送http请求
 * @param request
 */
public <T> void sendRequest(Request<T> request) {
	if (sRequestQueue == null) {
        sRequestQueue = Volley.newNoCacheRequestQueue(mContext);
    }
	request.setTag(this);
    sRequestQueue.add(request);
}
 
Example 16
Source Project: EasyVolley   Source File: EasyVolley.java    License: Apache License 2.0 5 votes vote down vote up
public static void initialize(Context appContext, int lruCacheSize) {
    if (mGlobalRequestQueue == null) {
        mGlobalRequestQueue = new com.github.asifmujteba.easyvolley.ASFRequestQueue(Volley.newRequestQueue(appContext,
                new HurlStack(), maxDiskCacheBytes));
    }

    if (lruCacheSize > 0) {
        getMemoryCache().setMaxSize(lruCacheSize);
    }
}
 
Example 17
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_network_image_view);
    RequestQueue queue = Volley.newRequestQueue(this);
    ImageLoader loader = new ImageLoader(queue, new NoImageCache());
    String url = "http://farm6.staticflickr.com/5026/5735032857_68a332481e_z.jpg";

    NetworkImageView imageView = (NetworkImageView) findViewById(R.id.image);

    imageView.setDefaultImageResId(R.drawable.ic_launcher);
    imageView.setErrorImageResId(R.drawable.ic_launcher);
    imageView.setImageUrl(url, loader);

}
 
Example 18
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act__ss_ssl_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) {
            
            // Replace R.raw.test with your keystore 
            InputStream keyStore = getResources().openRawResource(R.raw.test);
            
            
            // 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_SsSslHttpClient.this,
                                     new ExtHttpClientStack(new SslHttpClient(keyStore, "test123", 44401)));

            StringRequest myReq = new StringRequest(Method.GET,
                                                    "https://ave.bolyartech.com:44401/https_test.html",
                                                    createMyReqSuccessListener(),
                                                    createMyReqErrorListener());

            queue.add(myReq);
        }
    });
}
 
Example 19
Source Project: m2x-android   Source File: VolleyResourcesSingleton.java    License: 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 20
public static RequestQueue getRequestQueue() {
    if (requestQueue == null) {
        synchronized (BaseVolleyApi.class){
            if (requestQueue == null)
                requestQueue = Volley.newRequestQueue(RootApplication.getInstance());
        }
    }
    return requestQueue;
}
 
Example 21
@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 22
Source Project: android-common-utils   Source File: RequestManager.java    License: 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 23
Source Project: CoolClock   Source File: NetworkService.java    License: 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 24
Source Project: Presentation   Source File: Huaban.java    License: 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 25
Source Project: EasyPay   Source File: VolleyClient.java    License: 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 26
Source Project: EasyPay   Source File: VolleyClient.java    License: 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 27
Source Project: Android-SDK   Source File: MyVolley.java    License: 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 28
Source Project: Gizwits-SmartBuld_Android   Source File: GosScheduleSiteTool.java    License: 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 29
Source Project: attendee-checkin   Source File: GutenbergApplication.java    License: 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 30
Source Project: nearbydemo   Source File: MainActivity.java    License: 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);

}