In my app I use webview to display webpages defined by user. IF webpage contains video the video doesn't stop after back is pressed and activity is stopped. I've solve this issue in older implementation (android.webkit.WebView) but now I'm facing this issue again in kitkat which uses webview from chromium package. Here is the code I'm using in older versions. I'm looking to do the same in >=4.4 android versions.
if(webView!=null){
try {
Class.forName("android.webkit.WebView")
.getMethod("onPause", (Class[]) null)
.invoke(webView, (Object[]) null);
} catch(ClassNotFoundException cnfe) {
} catch(NoSuchMethodException nsme) {
} catch(InvocationTargetException ite) {
} catch (IllegalAccessException iae) {
}
}
Hmmm... how about you try loading a bogus url, forcing the webview to dump the current webpage:
myWebView.loadUrl("about:blank");
you have to stop webview onpause
#Override
public void onPause() {
// TODO Auto-generated method stub
try {
webView.loadUrl("about:blank");
} catch (Exception e) {
}
super.onPause();
}
Related
I'm building a DPC (Device Policy Controller), and one of the issues I'm seeing is that while the Play Store and Play Services are being updated, the Google Contact Sync service crashes -- leaving the typical crash dialog on the screen. Since part of the idea of the initial set up process is to have as little user interaction as possible, how can I dismiss this dialog programmatically (since I seem to be pretty much guaranteed that this will happen)?
I've tried dismissing system dialogs...
ctx.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
... but that doesn't seem to do the trick.
Since this is a DPC, anything that requires device ownership/administration is fine.
edit: Usually I have no UI on screen at the time, so if one is necessary please do mention it. Also, preferably the solution should work on at least 6.0+, if not 4.0+.
Try to do it onWindowsFocusChanged method like this for example :
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (!hasFocus) {
Intent ctx= new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(ctx);
}
}
I'm not sure about app crash Dialog but maybe it'll help you
AppErrorDialog can be dismissed by broadcasting ACTION_CLOSE_SYSTEM_DIALOGS if Android version is N.
ctx.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
However, AppErrorDialog won't be displayed if phone is locked.
public boolean canShowErrorDialogs() {
return mShowDialogs && !mSleeping && !mShuttingDown
&& mLockScreenShown != LOCK_SCREEN_SHOWN;
} // ActivityManagerService
Please try this code.
try {
Class ActivityManagerNative = Class.forName("android.app.ActivityManagerNative");
Class IActivityManager = Class.forName("android.app.IActivityManager");
Method getDefault = ActivityManagerNative.getMethod("getDefault", null);
Object am = IActivityManager.cast(getDefault.invoke(ActivityManagerNative, null));
Method closeSystemDialogs = am.getClass().getMethod("closeSystemDialogs", String.class);
closeSystemDialogs.invoke(am, "DPC close");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Testing presence of videeditor_jni Native Library in system libraries by
static {
try {
if (System.getProperty("videoeditor_jni") != null) {
System.loadLibrary("videoeditor_jni");
} else {
PreferenceManager.setLibraryFlag(false);
}
} catch (Exception e) {
PreferenceManager.setLibraryFlag(false);
}
}
while running this code i've got UnsatisfiedException on library in logcat.
though I've put conditions and try..catch it is checking if condition and then Force Close. why didn't go into catch?? any reason? tried UnsatisfiedException, RuntimeException, Exception, Error but not anything called in catch.. need help .
To Catch exception stackTrace use method printStackTrace(). like as belows
write this Application class onCreate method.
public void onCreate()
{
super.onCreate();
....
try {
if (System.getProperty("videoeditor_jni") != null) {
System.loadLibrary("videoeditor_jni");
} else {
PreferenceManager.setLibraryFlag(false);
}
} catch (Exception e) {
e.printStackTrace.
}
}
I am doing a project related to live wallpaper, in that camera was set as wallpaper, so in my app camera was running continuously, if user set camera as wallpaper, after he opening the camera it will shows the camera failed to load error,
so, i am using the following code to avoid this error:
public void onVisibilityChanged(boolean visible) {
if (visible){
try {
mCamera.reconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else{
try {
mCamera.unlock();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
But my problem is could not unlock the camera object to other apps use the camera.
can any one give me an idea how can i do this?
You cannot access the object used by the native camera app or other apps to access camera. When you create mCamera, you are creating your own object which is used by your app. At a time, only one object can access a particular camera resource, and you have no control over other objects of other apps accessing that camera resource.
If you want avoid the failed to load error, you need to release your camera object before you open another app which uses camera resource. But then I do not think your main objective will be accomplished.
I am using same method with small modifications to solve the issue, i was doing following changes in the code
public void onVisibilityChanged(boolean visible) {
// TODO Auto-generated method stub
super.onVisibilityChanged(visible);
if (visible) {
try {
"open camera object"
}catch (Exception e) {
e.printStackTrace();
}
}else {
try {
"release the camera object"
}catch (RuntimeException e) {
e.printStackTrace();
}
}
}
I'm testing playing online video using chromecast.
After onRouteSelected(), I create the ApplicationSession and attach a MediaProtocalMessageStream;
Then I called mSession.startSession(); with no APP_ID, so I assume the build-in app inside chromecast play the video for me. This code works perfect and I can play online mp4 videos without writing my own receiver.
But, When I try to leave the video play app, I can't go back anymore, there is always an error message comes from onSessionStartFailed() which says
StartSessionTask failed with error: failed to start application: no
application is running
I don't remember how the first time I got into the video play app, which I don't leave for few day.
But I do know how I leave it, Here is what I did before I can never startSession again:
open Youtube app, get a deviced connected
play some youtube videos
disconnected from a chormecast, then the chromecast return to the starting page
So, doesn't anybody know what's going on here? How to open the build-in video app again?
By the way, My chromecast get a system update just after I return to the starting page, I don't know if google update something cause startSession() fail.
Below is the code I startSession and attach a mediaStream.
mSession = new ApplicationSession(mCastContext, mSelectedDevice);
ApplicationSession.Listener listener = new ApplicationSession.Listener() {
#Override
public void onSessionStarted(ApplicationMetadata appMetadata) {
mChannel = mSession.getChannel();
mStream = new MediaProtocolMessageStream();
mChannel.attachMessageStream(mStream);
if (mStream.getPlayerState() == null) {
ContentMetadata metaData = new ContentMetadata();
metaData.setTitle("Test Video");
String url = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_planet.mp4";
try {
mCommand = mStream.loadMedia(url, metaData, true);
mCommand.setListener(new MediaProtocolCommand.Listener() {
#Override
public void onCompleted(MediaProtocolCommand arg0) {
onSetVolume(0.5);
}
#Override
public void onCancelled(MediaProtocolCommand arg0) {
}
});
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
#Override
public void onSessionStartFailed(SessionError error) {
Log.d("TEST", "Session Started failed");
}
#Override
public void onSessionEnded(SessionError error) {
Log.d("TEST", "Session Started end");
}
};
mSession.setListener(listener);
try {
mSession.startSession();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
You will have to use your own app id and own receiver. Google's default receiver doesn't play video streams anymore (it used to). It only handles Chrome tab mirroring now.
i tried out its not working anyone can help me out
public void googlefunc(View v)
{
try {
AddThis.shareItem(this, "googleplus", mUrl, mShareTitle,
mShareDescription);
}
catch (ATDatabaseException e) {
e.printStackTrace();
}
catch (ATSharerException e) {
e.printStackTrace();
}
}
You have to use google_plusone (or google_plusone_share) instead of googleplus.
See the list of the available service (and search for google_plusone to find the right row).