Java application Android Studio, displays a pdf file in the application

Hello, I am writing a hospital application that should open a Pdf file (online) with the correct calendar week presented in my code.

he should display the pdf file immediately in the application, instead of trying to download it from a link or ask to open it using an external pdf viewer.

The application should display what food you need to buy in the dining room every day, as shown in the downloaded pdf file.

I tried to use classes like PDFRendererBasic, but since I am pretty new to Android Studio, I have not yet learned how to implement this in my code for my application to work.

In addition, I found out that I can open a pdf file with a code like

public class MyPdfViewActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    WebView mWebView=new WebView(MyPdfViewActivity.this);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setPluginsEnabled(true);
    mWebView.loadUrl("https://docs.google.com/gview?embedded=true&      url="+LinkToPDF);
    setContentView(mWebView);
  }
}

, - / ( ), , .

:

public void MensaEssensplan (View view) {
Calendar calendar = new GregorianCalendar(Locale.GERMAN);

Date date = calendar.getTime();

int jahresWoche = calendar.get(Calendar.WEEK_OF_YEAR);

String kw = (String.valueOf(jahresWoche));

//fills algorithm with correct week of year, because each week a new canteen plan is uploaded

String rawLink = "https://intranet.uke.de/dateien/tochtergesellschaften/kge-klinik-gastronomie-eppendorf/ma_kw_"+kw+".pdf";
Intent browserIntent=new Intent(Intent.ACTION_VIEW,Uri.parse(rawLink));
startActivity(browserIntent);
}

//opens pdf file with correct week of year ending in the pdf link.

, - , .

+4

Source: https://habr.com/ru/post/1664183/


All Articles