1/ use the permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.INTERNET" />
2/ Implement this.
implementation ("com.github.CodeWithTamim:NasaDownloader:1.0.0")
3/ use maven url
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url = uri("https://www.jitpack.io" ) }
}
}
4/ xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="10dp"
android:gravity="center"
android:orientation="vertical">
<EditText
android:id="@+id/urlED"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="input image url..."
android:inputType="text" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/downlaodBTN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#4CAF50"
android:padding="5dp"
android:text="Download" />
</LinearLayout>
</RelativeLayout>
1/ Kotlin
package com.tutorialb.testkotlin
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import com.nasahacker.downloader.NasaDownloader
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
val downloadBTN : Button = findViewById(R.id.downlaodBTN)
val urlED: TextView = findViewById(R.id.urlED)
val downloader = NasaDownloader("SavingDirName")
downloadBTN.setOnClickListener {
val imageURL= urlED.text.toString()
if (!downloader.isPermissionGranted(this)) {
downloader.requestPermission(this);
} else {
downloader.downloadImage(this, imageURL, NasaDownloader.IMAGE_TYPE.JPEG);
}
}
}
}