Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const val EXTRA_DOWNLOAD_STATUS ="download_Status"
- class MainActivity : AppCompatActivity() {
- private val downloadReceiver = object : BroadcastReceiver(){
- override fun onReceive(p0: Context?, p1: Intent?) {
- Toast.makeText(this@MainActivity, "proses",Toast.LENGTH_SHORT).show()
- var selesai = p1?.getBooleanExtra(EXTRA_FINISH,false)
- var persenSelesai = p1?.getIntExtra(EXTRA_PERSEN,0)
- myProgerss.progress = persenSelesai!!
- if(selesai!!){
- Toast.makeText(this@MainActivity, "Selesai Download",Toast.LENGTH_SHORT).show()
- }
- }
- }
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- val mDownloadService = Intent (this, MyDownloadService::class.java)
- startMyService.setOnClickListener {
- Toast.makeText(this@MainActivity, "Download Dimulai",Toast.LENGTH_SHORT).show()
- startService(mDownloadService)
- }
- stopMyService.setOnClickListener {
- stopService(mDownloadService)
- }
- val filterReceiver = IntentFilter(EXTRA_DOWNLOAD_STATUS)
- filterReceiver.setPriority(Integer.MAX_VALUE)
- registerReceiver(downloadReceiver,filterReceiver)
- }
- override fun onDestroy() {
- unregisterReceiver(downloadReceiver)
- super.onDestroy()
- }
- }
- private operator fun Int.invoke(maX_VALUE: Int) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement