Java 在按钮上单击重定向以从链接打开PDF
我想创建一个带有按钮和文本框的java页面 因此,当用户在文本框中写入数字1,然后按下按钮时 它将重定向他以从中打开pdf文件 前任: www.mywebsite/myfile1.pdf 当用户在文本框中写入数字2,然后按下按钮时 它会将他重定向到打开pdf文件 www.mywebsite/myfile2.pdf 多谢各位 AndroidManifest.xmlJava 在按钮上单击重定向以从链接打开PDF,java,android-studio,pdf,android-intent,Java,Android Studio,Pdf,Android Intent,我想创建一个带有按钮和文本框的java页面 因此,当用户在文本框中写入数字1,然后按下按钮时 它将重定向他以从中打开pdf文件 前任: www.mywebsite/myfile1.pdf 当用户在文本框中写入数字2,然后按下按钮时 它会将他重定向到打开pdf文件 www.mywebsite/myfile2.pdf 多谢各位 AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:and
<?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>
如果您的pdf源是一个链接,您可以先下载pdf或使用WebView打开它。是一些可能有用的链接 可能重复的
<?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>
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");
{
}
}
}