• Не открывается файл менеджер при клике по input тип file в WebView. Что можно сделать?

    @anton106 Автор вопроса
    Вот код оставлю может кому еще пригодится, нашел на буржуйском форуме:
    Не подходит для 4.4
    public class Web extends Activity {
    	
    	WebView web;
    	
    	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_web);
    		
    				
    		Intent intent = getIntent();
    		
    		String mUrl = intent.getStringExtra("nameUrl"); // требуемый урл
    		String mTitle = intent.getStringExtra("conTitle"); // заголовок активити
    		
    		if(mTitle!="") {
    			setTitle(mTitle);
    		}
    		
    		WebView myWebView = (WebView) findViewById(R.id.webview);
    		myWebView = new WebView(this);
    		WebSettings webSettings = myWebView.getSettings();
    		webSettings.setAllowFileAccess(true);
    		//webSettings.setBlockNetworkLoads(true);
    		webSettings.setLoadWithOverviewMode(true);
    		myWebView.setWebViewClient(new WebViewClient());
    		myWebView.loadDataWithBaseURL(INPUT_SERVICE, null, null, null, null);
    		webSettings.setJavaScriptEnabled(true);
    		myWebView.loadUrl(mUrl);
    		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/*");  
    	            Web.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("*/*");
    	           Web.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/*");  
    	               Web.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), Web.FILECHOOSER_RESULTCODE );
    
    	           }
    
    	    });
    		setContentView(myWebView);  
    	}
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// Inflate the menu; this adds items to the action bar if it is present.
    		getMenuInflater().inflate(R.menu.web, menu);
    		return true;
    	}
    
    	@Override
    	public boolean onOptionsItemSelected(MenuItem item) {
    		// Handle action bar item clicks here. The action bar will
    		// automatically handle clicks on the Home/Up button, so long
    		// as you specify a parent activity in AndroidManifest.xml.
    		int id = item.getItemId();
    		if (id == R.id.action_settings) {
    			return true;
    		}
    		return super.onOptionsItemSelected(item);
    	}
    }
    Ответ написан
    Комментировать