Mostly my android webview works fine when fullscreening videos but there are some videos where it encounters problems, some I've already fixed, some I can't
1) Fullscreen button doesn't always trigger onShowCustomView. FIXED: Updating Chrome from the Google app store fixes this bug
2) Video goes fullscreen and you can hear the audio but sometimes the whole screen is black, you cannot even see the video player UI. Example: https://www.engadget.com/2019/05/22/vader-immortal-review-oculus-quest-vr/
I have a hack fix for this at the moment by resizing the view after a 2s delay but I'd obviously prefer a more robust solution
3) Video goes fullscreen temporarily but then closes itself immediately. This only happens occasionally but I've seen it happen when opening vimeo videos from twitter. It's not consistent so you'll have to click through a few https://mobile.twitter.com/search?q=Vimeo&src=typed_query
Any idea how I can make this work more consistently?
My custom web chrome client:
public void onShowCustomView(View paramView, CustomViewCallback paramCustomViewCallback)
{
if (this.mCustomView != null)
{
onHideCustomView(); // I verified this wasn't the cause of point 3
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = browserUi.getBrowser().getWindow().getDecorView().getSystemUiVisibility();
previousOrientation = browserUi.getBrowser().getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
FrameLayout decorView;
if(browserUi.isPreviewWindow()){
decorView = browserUi.getBrowser().findViewById(R.id.prev_window_fullscreen_video_container);
}else {
decorView = browserUi.getBrowser().findViewById(R.id.fullscreen_video_container);
}
decorView.setVisibility(View.VISIBLE);
decorView.addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
if(!browserUi.isPreviewWindow()) {
this.mCustomView.setKeepScreenOn(true); // prevents sleep while viewing
int flags = SYSTEM_UI_FLAG_LOW_PROFILE | SYSTEM_UI_FLAG_HIDE_NAVIGATION;
flags |= SYSTEM_UI_FLAG_FULLSCREEN;
flags |= SYSTEM_UI_FLAG_LAYOUT_STABLE;
flags |= SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
flags |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
flags |= SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(flags);
int screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
browserUi.getBrowser().setRequestedOrientation(screenOrientation);
}
}
Related
I've got a dental camera and iam try to get windows to press space when the camera button is pressed
I have the OEM software and driver installed, it works perfect, gets the feed and makes a snapshot when camera button is pressed. I need to use another software for the feed and the snapshot, the software gets the feed but doesn't react to camera button, it only reacts to space key press(part of the oem driver), so my way of solving this was getting the device by product id and listening the button press event and remapping it space press.
I am pretty much stuck at this point.
How can I listen on events coming from the device I've got?
public static Device findDCam(){
// Create the libusb context
Context context = new Context();
// Initialize the libusb context
int result = LibUsb.init(context);
if (result < 0)
{
throw new LibUsbException("Unable to initialize libusb", result);
}
// Read the USB device list
DeviceList list = new DeviceList();
result = LibUsb.getDeviceList(context, list);
if (result < 0)
{
throw new LibUsbException("Unable to get device list", result);
}
try
{
// Iterate over all devices and list them
for (Device device: list)
{
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result < 0)
{
throw new LibUsbException(
"Unable to read device descriptor", result);
}
if(descriptor.idProduct()== -3810){
System.out.println("D cam found");
return device;
}
}
}
finally
{
// Ensure the allocated device list is freed
LibUsb.freeDeviceList(list, true);
}
// Deinitialize the libusb context
LibUsb.exit(context);
return null;
}
I've also thought that maybe it's impossible using usb4java since as far as i understood, if i want to listen on the usb port i need to take control from the driver and then its pointless.
Maybe iam going all wrong and i should use the driver instead?
Or maybe there is an app that can read button presses from a specific device and remap it?
If the camera has a standard driver, this should work through this video capture SDK. To quick test it, run the demo executable included in the package, select the camera in the list, check the "webcam snapshot button" checkbox and start the camera. Then press the camera button to test the snapshot.
I have created an application which uses the camera intent to capture photographs. The photographs are being captured fine and saved to respective folders. The issue is that only on Samsung S Series devices, the images ate always in Portrait mode, even if the image is captured in landscape mode. Due to this issue, I have tried to get the orientation of the captured images and then change them to my requirements accordingly, but the orientation always returns zero.
I am trying to use this method:
public static int getRotation(Context context,Uri selectedImage) {
int rotation =0;
ContentResolver content = context.getContentResolver();
Cursor mediaCursor = content.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] { "orientation", "date_added" },null, null,"date_added desc");
if (mediaCursor != null && mediaCursor.getCount() !=0 ) {
while(mediaCursor.moveToNext()){
rotation = mediaCursor.getInt(0);
break;
}
}
mediaCursor.close();
return rotation;
}
The method always returns 0 no matter what is the orientation of the image. Where am I going wrong? What is to be done to address the issue?
Samsung likes to break stuff. I have a similar experience before.
But the camera intent should have saved the orientation info as Exif in the jpg file.
As you are using camera Intent, you should have the File Uri. Then you can use ExifInterface to extra the rotation directly from the file.
http://developer.android.com/reference/android/media/ExifInterface.html
Sample code
ExifInterface exif = new ExifInterface(file);
int oridentation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
//do what you want
break;
case ExifInterface.ORIENTATION_ROTATE_180:
//do what you want
break;
....
}
My goal is the following, I want to give the user the following options in preferences:
Play sounds: "Always on speaker" or "Use Bluetooth when available"
Use stream: STREAM_MUSIC, STREAM_ALARM, STREAM_NOTIFICATION or STREAM_RING
My first problem is that when a user has a (Lollipop) device connected to an a2dp enabled device (car stereo), I can't seem to get the sound to get played through the device speaker. (The sound also isn't being played through the a2dp device)
The second problem I encounter is that setStreamType somehow stopped working since Lollipop? On Lollipop setStreamType is ignored and sound is always played through AudioManager.STREAM_MUSIC? (On device pre-Lollipop the same code still works)
private void playSound() {
try {
if (am == null) am = (AudioManager) _context.getSystemService(Context.AUDIO_SERVICE);
if (am.isWiredHeadsetOn() || am.isBluetoothA2dpOn()){
am.setWiredHeadsetOn(false);
am.setBluetoothScoOn(false);
// am.setMode(AudioManager.MODE_IN_CALL); // bel speaker
// am.setSpeakerphoneOn(false); // bel speaker
am.setMode(AudioManager.MODE_IN_CALL); // media speaker
am.setSpeakerphoneOn(true); // media speaker
} else {
// am.setMode(AudioManager.MODE_IN_CALL); // bel speaker
// am.setSpeakerphoneOn(false); // bel speaker
am.setMode(AudioManager.MODE_NORMAL); // media speaker
am.setSpeakerphoneOn(true); // media speaker
}
Class audioSystemClass = Class.forName("android.media.AudioSystem");
Method setForceUse = audioSystemClass.getMethod("setForceUse",
int.class,
int.class);
// 1 == FOR_MEDIA, 10 == FORCE_NO_BT_A2DP (FORCE_SPEAKER would be 1).
setForceUse.invoke(null, 1, 1);
alarmsound = _prefs.getString("alarm", alarmsound);
as = Uri.parse(alarmsound);
if (mp == null) mp = MediaPlayer.create(_context, as);
mp.reset();
if (alarmsound.startsWith("content://settings/system/"))
mp.setDataSource(_context, Uri.parse("android.resource://nl.xxxxxxxx.xxxxxxxx/raw/beep"));
else setMediaPlayerDataSource(_context, mp, as.toString());
mp.setAudioStreamType(Globals.AudioStreamType);
mp.prepare();
long alarmDuration = mp.getDuration();
mp.start();
}
From the Globals class:
public static int AudioStreamType = AudioManager.STREAM_MUSIC; (this can be changed by the user to the other stream types)
I declared uses-permission android.permission.MODIFY_AUDIO_SETTINGS in the Manifest.
Hopefully someone can point me in the right direction.
I'm trying to load installed packages' icons into a listview, but they are not showing in anyway, searched and used everything I found on the web but they just won't show, while they work if I use
R.drawable.ic_launcher
So I guess it's not a layout-related issue.
Here's the code I'm using
for(int i = 0; i < numeroElementi; i++){
boolean nonSystem = (packages.get(i).flags & ApplicationInfo.FLAG_SYSTEM) == 0;
if(nonSystem == true){
HashMap<String,Object> app = new HashMap<String,Object>();
app.put("appName", packages.get(i).loadLabel(pm)); // these both work
app.put("appPackageName", packages.get(i).packageName);
try {
//app.put("appIcon", pm.getApplicationIcon(packages.get(i).packageName));
//app.put("appIcon", packages.get(i).icon + "");
//app.put("appIcon", packages.get(i).loadIcon(pm));
app.put("appIcon",packages.get(i).icon);
//app.put("appIcon", R.drawable.ic_launcher); <- this works
} catch (NameNotFoundException e) {
app.put("appIcon", R.drawable.ic_launcher);
}
installedList.add(app);
}
}
Is then there another way to grab the icon? As said earlier, if I force the ic_launcher icon, then it works... testing with packages.get(i).icon I found out that some of the voices have got the ic_launcher icon shown, so I thought that method just directed to that specific icon... anyone can help me get this work, please?
I currently start a Ringtone on Android and it plays fine.
However when I try to stop the ringtone it doesn't stop or atleast doesn't stop straight away, it will keep in playing until it just plays out.
Here is how I set up the Ringtone:
int rm = audio_service.getRingerMode();
int vs = audio_service.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER);
android.os.Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if ((rm == AudioManager.RINGER_MODE_VIBRATE ||
(rm == AudioManager.RINGER_MODE_NORMAL && vs == AudioManager.VIBRATE_SETTING_ON)))
v.vibrate(vibratePattern,1);
if (audio_service.getStreamVolume(AudioManager.STREAM_RING) > 0) {
oRingtone = RingtoneManager.getRingtone(this, Settings.System.DEFAULT_RINGTONE_URI);
oRingtone.setStreamType(AudioManager.STREAM_RING);
oRingtone.play();
}
And here is how I try to stop it
if (CallDialogActivity.oRingtone != null) {
Log.d("RINGTONE", "Into Ringtone if");
Ringtone ringtone = CallDialogActivity.oRingtone;
oRingtone = null;
ringtone.stop();
}
Has anyone come across similiar problems or see any mistakes in my code?
EDIT:
Just to add I have added logging to see if ringtone.isPlaying() returns true or false after I call ringtone.stop() and it returns false, however the tone keeps playing for a couple of seconds (3 - 5 seconds) after before stopping
For anyone that comes across this:
I had to use the RingTone manager to help stop the ringtone.
Adding the following line sorted it out
ringtoneManager.stopPreviousRingtone();