我正在尝试创建一个import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.webkit.PermissionRequest;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity implements MyWebChromeClient.ProgressListener{
private ProgressBar chromeProgressBar;
WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myWebView = (WebView) findViewById(R.id.webview);
//chromeProgressBar = (ProgressBar) findViewById(R.id.progressBarChrome);
//Settings
WebSettings webSettings = myWebView.getSettings();
myWebView.getSettings().setTextSize(WebSettings.TextSize.NORMAL);
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setAllowFileAccessFromFileURLs(true);
}
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setAllowFileAccess(true);
//webSettings.setLoadsImagesAutomatically(true);
//inizialize client
//load website by URL
myWebView.loadUrl("https://www.voyage-app.eu/asti-app/admin/index.php");
//register token for notification
// this.onStart();
chromeProgressBar = (ProgressBar) findViewById(R.id.progressBar);
myWebView.setWebChromeClient(new WebChromeClient() {
// Grant permissions for cam
@Override
public void onPermissionRequest(final PermissionRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
request.grant(request.getResources());
}
}
});
myWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
chromeProgressBar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
chromeProgressBar.setVisibility(View.GONE);
}
});
}
@Override
public void onUpdateProgress(int progressValue) {
chromeProgressBar.setProgress(progressValue);
if (progressValue == 100) {
chromeProgressBar.setVisibility(View.INVISIBLE);
}
}
public class WebViewController extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public void onBackPressed()
{
if(myWebView.canGoBack())
myWebView.goBack();
else
super.onBackPressed();
}
}
应用。我试图添加对清单的访问权限,但它没有改变任何东西。在相机工作的Chrome浏览器上,我无法理解我该怎么做。
1。这是清单:
PHP
2。主要活动
Intent i = new Intent(apples.this,Bacon.class);
final EditText applesInput = (EditText) findViewById(R.id.applesInput);
String userMessage = applesInput.getText().toString();
i.putExtra("applesMessage",userMessage);
startActivity(i);
我认为我不应该发布final TextView baconText = (TextView) findViewById(R.id.baconText);
Bundle applesData = getIntent().getExtras();
if(applesData==null){
Toast.makeText(Bacon.this, "Love u", Toast.LENGTH_SHORT).show();
return;
}
String applesMessage = applesData.getString("applesMessage");
baconText.setText(applesMessage);
文件,因为在Chrome浏览器页面上有效。它发生在这样:
答案 0 :(得分:1)
修正了它。我不得不在代码中加入渗透:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int hasCameraPermission = checkSelfPermission(Manifest.permission.CAMERA);
List<String> permissions = new ArrayList<String>();
if (hasCameraPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.CAMERA);
}
if (!permissions.isEmpty()) {
requestPermissions(permissions.toArray(new String[permissions.size()]), 111);
}
}
但为了实现这一点,我还必须添加清单文件:
import android.Manifest;