0

I want to create a java page with a Button and a TextBox So that when the user writes the number 1 in the TextBox and then presses the Button It will redirect him to open a pdf file from ex: www.mywebsite / myfile1.pdf When the user writes the number 2 in the TextBox and then presses the Button It will redirect him to open pdf file from www.mywebsite / myfile2.pdf

Thank you

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapplication">
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Enter file number"
        android:inputType="number"
        app:layout_constraintBottom_toTopOf="@+id/Open"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.503"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.507" />

    <Button
        android:id="@+id/Open"
        android:layout_width="138dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="276dp"
        android:text="Open"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>

Main_activity.java

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
Button Open;
EditText Filenumber;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Open=(Button)findViewById(R.id.Open);
        Filenumber=(EditText)findViewById(R.id.editText);
        Open.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }
    public void open(){
        if(Filenumber.equals("1234"))
            Uri.parse("http://www.xmlpdf.com/manualfiles/hello-world.pdf");
        if(Filenumber.equals("12345"))
            Uri.parse("http://www.google.com");

        {
        }
    }
}
sam
  • 3
  • 5
  • Possible duplicate of [Open online pdf file through android intent?](https://stackoverflow.com/questions/23240469/open-online-pdf-file-through-android-intent) – Pratham Khurana Apr 19 '18 at 13:59

1 Answers1

1

If your pdf source is a link, you can either download the pdf first or open it using WebView. Here is some link that might be of help.

Adn
  • 106
  • 3