Online URl Read Or Download In Android

Here I providing you code for open any type of Video, music, docs, image, pdf, ect. Android Internal and External storage. The Download file is saved to the memory in the android device.

1. VideoMusicPDFWordFile

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;

public class VideoMusicPDFWordFile extends AppCompatActivity {
Context context;
    Button video,music,pdf,excel,image,word;
    private static final int PERMISSION_REQUEST_CODE = 1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_video_music_pdfword_file);
        context = this;

        if (Build.VERSION.SDK_INT >= 23)
        {
            if (checkPermission())
            {
                // Code for above or equal 23 API Oriented Device
                // Your Permission granted already .Do next code
            } else {
                requestPermission(); // Code for permission
            }
        }
        else
        {

            // Code for Below 23 API Oriented Device
            // Do next code
        }


        video = (Button) findViewById(R.id.video);
        music = (Button) findViewById(R.id.music);
        pdf = (Button) findViewById(R.id.pdf);
        excel = (Button) findViewById(R.id.excel);
        image = (Button) findViewById(R.id.image);
        word = (Button) findViewById(R.id.word);

        video.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent ii = new Intent(getBaseContext(), VideoFile.class);
                startActivity(ii);
            }
        });

        music.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent ii = new Intent(getBaseContext(), ListenMusic.class);
                startActivity(ii);
            }
        });

        pdf.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent ii = new Intent(getBaseContext(), PDF.class);
                startActivity(ii);
            }
        });

        excel.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent ii = new Intent(getBaseContext(), Excel.class);
                startActivity(ii);
            }
        });

        image.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent ii = new Intent(getBaseContext(), Image.class);
                startActivity(ii);
            }
        });

        word.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent ii = new Intent(getBaseContext(), Word.class);
                startActivity(ii);
            }
        });
    }






    private boolean checkPermission() {
        int result = ContextCompat.checkSelfPermission(VideoMusicPDFWordFile.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (result == PackageManager.PERMISSION_GRANTED) {
            return true;
        } else {
            return false;
        }
    }

    private void requestPermission() {

        if (ActivityCompat.shouldShowRequestPermissionRationale(VideoMusicPDFWordFile.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            Toast.makeText(VideoMusicPDFWordFile.this, "Write External Storage permission allows us to do store images. Please allow this permission in App Settings.", Toast.LENGTH_LONG).show();
        } else {
            ActivityCompat.requestPermissions(VideoMusicPDFWordFile.this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSION_REQUEST_CODE);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        switch (requestCode) {
            case PERMISSION_REQUEST_CODE:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Log.e("value", "Permission Granted, Now you can use local drive .");
                } else {
                    Log.e("value", "Permission Denied, You cannot use local drive .");
                }
                break;
        }
    }
}

2. build

apply plugin: 'com.android.application'

ext {
    PUBLISH_VERSION = '0.3.0'
    TARGET_SDK = 25
    BUILD_TOOLS = "24.0.3"
    GOOGLE_LIBS = "25.0.0"
}

android {
    compileSdkVersion TARGET_SDK
    buildToolsVersion BUILD_TOOLS
    defaultConfig {
        applicationId "com.tutorialsee.video_music_pdf_msword_player"
        minSdkVersion 14
        targetSdkVersion TARGET_SDK
        versionCode 15
        versionName PUBLISH_VERSION
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'me.zhanghai.android.materialprogressbar:library:1.1.7'
    compile "com.android.support:appcompat-v7:$GOOGLE_LIBS"
    compile 'com.afollestad.material-dialogs:core:0.9.1.0'
    compile "com.squareup.picasso:picasso:2.4.0"
    testCompile 'junit:junit:4.12'
}

3. AndroidManifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tutorialsee.video_music_pdf_msword_player">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".VideoFile"
            android:configChanges="orientation|keyboardHidden|screenLayout|screenSize" />
        <activity android:name=".ListenMusic" />
        <activity android:name=".VideoMusicPDFWordFile">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".PDF" />
        <activity android:name=".Excel" />
        <activity android:name=".Image" />
        <activity android:name=".Word"></activity>
    </application>

</manifest>