I got the problem, that I need to close my MainActivity.java, but it wont work. Everytime I try to build the app it say's, that I didnt closed it right and Android Studio wants me to use ) instead of }. I would be happy if u could help me out. Thanks in advanced. Here is the code:
package com.privat.kircheimnetzedit;
import static android.view.KeyEvent.KEYCODE_BACK;
import androidx.appcompat.app.AppCompatActivity;
import android.app.DownloadManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.KeyEvent;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import java.util.concurrent.atomic.AtomicBoolean;
public class MainActivity<notificationId> extends AppCompatActivity {
private static final int TIME_LIMIT = 1500;
private static long backPressed;
private WebView getHomepage;
WebView homepage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
homepage = findViewById(R.id.homepage);
homepage.getSettings().setJavaScriptEnabled(true);
homepage.setWebViewClient(new WebViewClient());
homepage.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Downloaddatei aus Kirche im Netz App");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
AtomicBoolean onKeyDown = new AtomicBoolean(false);
int keyCode, KeyEvent;
android.view.KeyEvent event;
if (event.getAction() == android.view.KeyEvent.ACTION_DOWN)
switch (keyCode) {
}
case KEYCODE_BACK:
if (homepage.canGoBack()) {
homepage.goBack();
} else {
finish();
}
return;
return;
onKeyDown(keyCode);
}
}
}
}
CodePudding user response:
Your switch case should have the "case" inside the "{" It should look like this:
switch (keyCode){
case 1:
//your code here
break;
case 2:
//your other code here
break;
}
Look here for reference: https://www.w3schools.com/java/java_switch.asp
CodePudding user response:
Try replacing
homepage.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Downloaddatei aus Kirche im Netz App");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
AtomicBoolean onKeyDown = new AtomicBoolean(false);
int keyCode, KeyEvent;
android.view.KeyEvent event;
if (event.getAction() == android.view.KeyEvent.ACTION_DOWN)
switch (keyCode) {
}
case KEYCODE_BACK:
if (homepage.canGoBack()) {
homepage.goBack();
} else {
finish();
}
return;
return;
onKeyDown(keyCode);
}
}
with
homePage.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "Downloaddatei aus Kirche im Netz App");
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
AtomicBoolean onKeyDown = new AtomicBoolean(false);
int keyCode, KeyEvent;
android.view.KeyEvent event;
if (event.getAction() == android.view.KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KEYCODE_BACK:
if (homepage.canGoBack()) {
homepage.goBack();
break;
} else {
finish();
break;
}
return;
}
return;
}
onKeyDown(keyCode);
}
}
Now this code will work completely fine!
