Created
November 22, 2022 06:24
-
-
Save NizarETH/f9daac7b1183e86d5b2525d568f551d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sans runTime permission | |
=================================== | |
Gradle | |
=================================== | |
implementation 'com.android.volley:volley:1.2.1' | |
=================================== | |
Manifest | |
=================================== | |
<uses-permission android:name="android.permission.INTERNET"/> | |
=================================== | |
MainActivity | |
=================================== | |
import android.os.Bundle | |
import android.view.View | |
import android.widget.Toast | |
import androidx.appcompat.app.AppCompatActivity | |
import com.android.volley.Request | |
import com.android.volley.Response | |
import com.android.volley.toolbox.StringRequest | |
import com.android.volley.toolbox.Volley | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
findViewById<View>(R.id.open_web).setOnClickListener { | |
// Instantiate the RequestQueue. | |
val queue = Volley.newRequestQueue(this) | |
val url = "https://gist.githubusercontent.com/NizarETH/4bdd464f3e5d026057fbcac960b85a5c/raw/40485eceefc6f938ec1558d4512d2f301f42f306/" | |
// Request a string response from the provided URL. | |
val stringRequest = StringRequest( | |
Request.Method.GET, url, | |
Response.Listener<String> { response -> | |
// Display the first 500 characters of the response string. | |
Toast.makeText(this@MainActivity, "Response is: ${response.substring(0, 500)}", Toast.LENGTH_LONG).show() | |
}, | |
Response.ErrorListener { | |
Toast.makeText(this@MainActivity, "That didn't work!", Toast.LENGTH_LONG).show() | |
}) | |
// Add the request to the RequestQueue. | |
queue.add(stringRequest) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment