I tried to take a screenshot in the internal storage during automation testing,but when run the test,it didn't show any error,but when I check the file,the screenshot didn't take successfully,I am so confused right now,please help me~
Here is part of my code:
I have my permission in my AndroidManifest.xml already
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS "/>
screenshot
UiDevice mDevice =UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.pressHome();
mDevice.takeScreenshot(new File("/sdcard/Pictures/test.png"));
sleep(3000);
I am sure the direction is not wrong cause I tried the same code before,it worked normally,but after few days I tired it again and it failed without showing any error.
Can you try
mDevice.takeScreenshot(new File("/sdcard/Download/test.png"));
sleep(3000);
I'm trying to make a app with WebView, but the website is using https, but the content (ex. mp3 file) uses http, so Android Lollipop won't load it because it is "Mixed Content". I tried to use onReceivedSslError handler.proceed();, but it doesn't load anything. Is there a way to fix it? or could I just make all websites loaded use http, so It doesn't show any errors?
Since Pie (API 29), all non-HTTPS traffic in app is now disabled by default.
If you're targeting API level 26 or above, you must first enable it in the manifest file. Add
android:usesCleartextTraffic="true"
into <application> tag.
Since Lollipop (API 21), WebView blocks all mixed content by default.
To change this behaviour, when you are targeting API level 21 or above, use:
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
In this mode, the WebView will attempt to be compatible with the
approach of a modern web browser with regard to mixed content. Some
insecure content may be allowed to be loaded by a secure origin and
other types of content will be blocked. The types of content are
allowed or blocked may change release to release and are not
explicitly defined.
In practice this should allow loading of images, videos, music etc. - all content that has low probability of being major security threat, when tampered/replaced by malicious third-party.
Alternatively use (strongly discouraged):
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
In this mode, the WebView will allow a secure origin to load content
from any other origin, even if that origin is insecure. This is the
least secure mode of operation for the WebView, and where possible
apps should not set this mode.
If your min API is less than 21 and cannot call setMixedContentMode directly, you can use reflection:
try {
Method m = WebSettings.class.getMethod("setMixedContentMode", int.class);
if ( m == null ) {
Log.e("WebSettings", "Error getting setMixedContentMode method");
}
else {
m.invoke(webView.getSettings(), 2); // 2 = MIXED_CONTENT_COMPATIBILITY_MODE
Log.i("WebSettings", "Successfully set MIXED_CONTENT_COMPATIBILITY_MODE");
}
}
catch (Exception ex) {
Log.e("WebSettings", "Error calling setMixedContentMode: " + ex.getMessage(), ex);
}
In android pie in addition to setting the mixed content mode, you also need to set the android:usesCleartextTraffic attribute in the AndroidManifest.
In your AndroidManifest.xml do:
<application
....
android:usesCleartextTraffic="true"
...>
and when setting up the webview, do:
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
to load it conditionally on API >= 21, you don't have to use reflection.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
}
I've recently migrated from Crosswalk to use the native WebView.
Had to fight with this issue for a few hours. The fix was to run clearCache() prior to setting the settings.
webView.clearCache(false); // <-- DO THIS FIRST
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
Go to manifest.xml and add the following line.
android:usesCleartextTraffic="true"
And in Java file of webview add this code.
webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
If you are running into this problem, just make sure you have installed the Ionic's WebView Cordova Plugin (https://github.com/ionic-team/cordova-plugin-ionic-webview). The easiest way is to check your package.json.
Once installed:
Open your config.xml file
Check if you have an entry for <preference name="Scheme">
If you do, check that the value is "https".
If you don't have it, then add this line:
<preference name="Scheme" value="https" />
Add this line:
<preference name="MixedContentMode" value="0" />
This solved the problem for me.
I am developing an app which is using 3 cameras. I have a device which have 3 cameras but when i call Camera.getNumberOfCameras() it always return 2 instead of returning 3. I dont know where the problem is. Can any one let me know if I am missing something.
Permission in manifest
<uses-feature android:name="android.hardware.camera">
<uses-permission android:name="android.permission.CAMERA" />
I found that it is showing 1 front and 1 back camera only. Please help
I have a problem with phonegap and $.get (jQuery). It's actually only a webapp which exists already but I want to bring it on my Android Smartphone.
So my $.get is working and I have this settings:
In res/xml/config.xml:
<access origin="*"/>
In AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
But it's not working :(
Edit 1 (17.11.2013 15:23):
alert("getData: "+searchTerm+" in "+language);
$.get("http://mysite.de/search.php", {art: searchTerm, lang: language}).done(function(data){
alert("daten: "+data);
}, "html");
alert("ready");
Only the first and the third alert is working.
The problem is
XMLHttpRequest cannot load http://mysite.de/search.php. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
You need to allow access to http://mysite.de/search.php from any domain
Allow it by adding code to your php page:
header("Access-Control-Allow-Origin: *");
What is the requirement to make use of this:
mMessageContentView = (WebView) findViewById(R.id.message_content);
mMessageContentView.getSettings().setBlockNetworkLoads(false);
Everytime I set setBlockNetworkLoads to false. My application crashes! If I set it to true, it works fine but my application can't load images over the network.
Is there something I need to do before hand before I can set it to false?
As correctly pointed out by Gallal - I should of made use of the logs. A quick command on dos:
adb logcat
Showed that my application was missing the internet permission in the manifest file. So adding the following to my android manifest solved my problem:
<uses-permission android:name="android.permission.INTERNET" />