Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends Activity {
- private WebView mywebview;
- private SwipeRefreshLayout swipeLayout;
- private ValueCallback<Uri> mUploadMessage;
- private final static int FILECHOOSER_RESULTCODE=1;
- @Override
- protected void onActivityResult(int requestCode, int resultCode,
- Intent intent) {
- if(requestCode==FILECHOOSER_RESULTCODE)
- {
- if (null == mUploadMessage) return;
- Uri result = intent == null || resultCode != RESULT_OK ? null
- : intent.getData();
- mUploadMessage.onReceiveValue(result);
- mUploadMessage = null;
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- //webview
- mywebview = (WebView) findViewById(R.id.webView);
- WebSettings webSettings = mywebview.getSettings();
- webSettings.setJavaScriptEnabled(true);
- mywebview.loadUrl("https://m.samods.ru/");
- mywebview.setWebChromeClient(new WebChromeClient()
- {
- //The undocumented magic method override
- //Eclipse will swear at you if you try to put @Override here
- // For Android 3.0+
- public void openFileChooser(ValueCallback<Uri> uploadMsg) {
- mUploadMessage = uploadMsg;
- Intent i = new Intent(Intent.ACTION_GET_CONTENT);
- i.addCategory(Intent.CATEGORY_OPENABLE);
- i.setType("image/*");
- MainActivity.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE);
- }
- // For Android 3.0+
- public void openFileChooser( ValueCallback uploadMsg, String acceptType ) {
- mUploadMessage = uploadMsg;
- Intent i = new Intent(Intent.ACTION_GET_CONTENT);
- i.addCategory(Intent.CATEGORY_OPENABLE);
- i.setType("*/*");
- MainActivity.this.startActivityForResult(
- Intent.createChooser(i, "File Browser"),
- FILECHOOSER_RESULTCODE);
- }
- //For Android 4.1
- public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){
- mUploadMessage = uploadMsg;
- Intent i = new Intent(Intent.ACTION_GET_CONTENT);
- i.addCategory(Intent.CATEGORY_OPENABLE);
- i.setType("image/*");
- MainActivity.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), MainActivity.FILECHOOSER_RESULTCODE );
- }
- });
- //setContentView(mywebview);
- //swipe refresh
- swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
- swipeLayout.setColorSchemeResources(R.color.colorPrimary);
- swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override
- public void onRefresh() {
- mywebview.loadUrl("javascript: loc = location.href; location.href=loc");
- //mywebview.loadUrl("javascript: window.location.reload();");
- }
- });
- mywebview.setWebViewClient(new WebViewClient() {
- @Override
- public void onPageFinished(WebView web, String url) {
- if (swipeLayout.isRefreshing()) {
- swipeLayout.setRefreshing(false);
- }
- }
- });
- }
- //back button
- @Override
- public void onBackPressed() {
- if(mywebview.canGoBack()) {
- //mywebview.goBack();
- mywebview.loadUrl("javascript: popstate();");
- } else {
- super.onBackPressed();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement