PDF downloading link is not working

I am making an android application with mySQL database. I have made a PDF report that is to be downloading with I click on a button. Well, I used that link it the google chrome in my android device it works well. But, when I tried to use the same link in my application it doesn’t seem to be working. What I have done so far is that I want the file to be downloaded by a click of a button. So, I made the following code:

public class MainActivity extends ActionBarActivity {

private Button button;
private String LOGIN_URL =
        "http://amjad-test.site40.net/arabictest.php";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    button = (Button) findViewById(R.id.mybutton) ;

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(LOGIN_URL));
            request.setTitle("File Downloading");
            request.setDescription("File is being Downloaded...");
            request.allowScanningByMediaScanner();
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
            String File_name = URLUtil.guessFileName(LOGIN_URL, null, MimeTypeMap.getFileExtensionFromUrl(LOGIN_URL));
            request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, File_name);
            DownloadManager manager = (DownloadManager) MainActivity.this.getSystemService(Context.DOWNLOAD_SERVICE);
            manager.enqueue(request);
            Toast.makeText(MainActivity.this, "Downloading", Toast.LENGTH_LONG).show();


        }
    });

   }

I exactly don’t know where the problem could be. Is it in the code or in my php file.


Source: php

Leave a Reply