Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:32:14+00:00 2026-06-10T06:32:14+00:00

I’m coding my very first Android app, a soundboard/ringtone app, and I’m having a

  • 0

I’m coding my very first Android app, a soundboard/ringtone app, and I’m having a problem with my Toast notification not showing up. I have a button that calls DownloadManager, downloads an mp3 from the internet, saves it to the sdcard, and assigns it as a ringtone. This all works fine, but I know I must unregisterReceiver after DownloadManager finishes. I want a Toast to pop up saying “Ringtone Has Been Set” once DownloadManager.STATUS_SUCCESSFUL comes thru, and it DOES work if I comment out my “onStop / unregisterReceiver” block. Once I reactivate that block, Toast does not display. I appreciate any help, and again, I am EXTREMELY new to android coding, or any programming at all. Thanks!

package com.gameringers.ffringers;

import java.io.File;


import android.app.Activity;
import android.app.DownloadManager;
import android.app.DownloadManager.Query;
import android.app.DownloadManager.Request;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;

import android.widget.Toast;

public class DownloadActivity extends Activity {
private long enqueue;
private DownloadManager dm;



/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    String songfile = intent.getStringExtra(FFVI.SONG_FILE);
    String songtitle = intent.getStringExtra(FFVI.SONG_TITLE);
    setContentView(R.layout.activity_download);

    BroadcastReceiver receiver = new BroadcastReceiver()

    {


        @Override
        public void onReceive(Context context, Intent intent)
        {



                Query query = new Query();

                Cursor c = dm.query(query);
                if (c.moveToFirst()) {
                    int columnIndex = c
                            .getColumnIndex(DownloadManager.COLUMN_STATUS);

                    if (DownloadManager.STATUS_SUCCESSFUL == c
                            .getInt(columnIndex)) {

                        Toast.makeText(getBaseContext(), "Ringtone Has Been Set!",
                                Toast.LENGTH_LONG).show();  

                          finish();

                    }

                  } 

                }   

           // }


    };  


    registerReceiver(receiver, new IntentFilter(
            DownloadManager.ACTION_DOWNLOAD_COMPLETE));


    String path=(Environment.getExternalStorageDirectory()+"/gameringers");
   // String filename="Test11"+".mp3"; 

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(path+songfile)));

    File k = new File(path, songfile);

    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
    values.put(MediaStore.MediaColumns.TITLE, (songtitle));
    values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
    values.put(MediaStore.Audio.Media.ARTIST, "N/A");
    values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
    values.put(MediaStore.Audio.Media.IS_ALARM, false);
    values.put(MediaStore.Audio.Media.IS_MUSIC, false);

    //Insert it into the database
    Uri newUri= this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);

    RingtoneManager.setActualDefaultRingtoneUri(
    this,
    RingtoneManager.TYPE_RINGTONE,
    newUri);


    onStop();
    {

        unregisterReceiver(receiver);
        super.onStop();
    }

}







public void setringtone(View v) {

    Intent intent = getIntent();
    String songfile = intent.getStringExtra(FFVI.SONG_FILE);
    String songtitle = intent.getStringExtra(FFVI.SONG_TITLE);
     Toast.makeText(getBaseContext(), songfile+songtitle,
            Toast.LENGTH_LONG).show();


    dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);


    Request request = new Request(
            Uri.parse("http://www.gameringers.com/ringers/ff/"+songfile));

    request.setDestinationInExternalPublicDir("/gameringers",songfile);

    enqueue = dm.enqueue(request);



}


} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:32:16+00:00Added an answer on June 10, 2026 at 6:32 am
    onStop();
    {
    
        unregisterReceiver(receiver);
        super.onStop();
    }
    

    Above code from the question looks weird.
    The right one should be

    /** Receiver for download completion */
    BroadcastReceiver mReceiver;
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        String songfile = intent.getStringExtra(FFVI.SONG_FILE);
        String songtitle = intent.getStringExtra(FFVI.SONG_TITLE);
        setContentView(R.layout.activity_download);
    
        mReceiver = new BroadcastReceiver()
    
        {
    
    
            @Override
            public void onReceive(Context context, Intent intent)
            {
                    Query query = new Query();
    
                    Cursor c = dm.query(query);
                    if (c.moveToFirst()) {
                        int columnIndex = c
                                .getColumnIndex(DownloadManager.COLUMN_STATUS);
    
                        if (DownloadManager.STATUS_SUCCESSFUL == c
                                .getInt(columnIndex)) {
    
                            Toast.makeText(getBaseContext(), "Ringtone Has Been Set!",
                                    Toast.LENGTH_LONG).show();  
    
                              finish();
    
                        }
    
                      } 
    
                    }   
    
               // }
    
    
        };  
    
    
        registerReceiver(receiver, new IntentFilter(
                DownloadManager.ACTION_DOWNLOAD_COMPLETE));
    
    
        String path=(Environment.getExternalStorageDirectory()+"/gameringers");
       // String filename="Test11"+".mp3"; 
    
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse(path+songfile)));
    
        File k = new File(path, songfile);
    
        ContentValues values = new ContentValues();
        values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
        values.put(MediaStore.MediaColumns.TITLE, (songtitle));
        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
        values.put(MediaStore.Audio.Media.ARTIST, "N/A");
        values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
        values.put(MediaStore.Audio.Media.IS_ALARM, false);
        values.put(MediaStore.Audio.Media.IS_MUSIC, false);
    
        //Insert it into the database
        Uri newUri= this.getContentResolver().insert(MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath()), values);
    
        RingtoneManager.setActualDefaultRingtoneUri(
        this,
        RingtoneManager.TYPE_RINGTONE,
        newUri);
    }
    
    @Override
    public void onStop();
    {
       unregisterReceiver(mReceiver);
       mReceiver = null;
       super.onStop();
    }
    
    
    public void setringtone(View v) {
    
        Intent intent = getIntent();
        String songfile = intent.getStringExtra(FFVI.SONG_FILE);
        String songtitle = intent.getStringExtra(FFVI.SONG_TITLE);
         Toast.makeText(getBaseContext(), songfile+songtitle,
                Toast.LENGTH_LONG).show();
    }
    

    So with the code You have currently You just call onStop() and unregister receiver right in Yours onCreate() method. I believe it’s just syntax error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.