I am making an application multi lingual and handling orientation as well and i want to logout the user if Locale is changed i implemented this but now when user change orientation then it will logout the user.
#Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
boolean deviceLanguageOverridenWithDefaultLanguage = PersistentManager.isDeviceLanguageOverridenWithDefaultLanguage();
if(deviceLanguageOverridenWithDefaultLanguage)
{
AppUtil.setApplicationLanguage(AppConstants.APPLICATION_DEFAULT_LANGUAGE);
}
if(AppUtil.isSupportedLanguage(newConfig.locale))
{
UIUtil.showLogoutAlertDialog(this, getString(R.string.dialog_log_out_message_change_language_log_out), getString(R.string.dialog_log_out_title_log_out), false);
}
}
Related
I want to implement kiosk mode on react native (android). I have implemented the functionality to pin/unpin application and check if lock task mode is active using activityManager.getLockTaskModeState, startLockTask & stopLockTask.
The problem is i cannot track when user unpin the app by pressing recencts/back buttons.
i tried to add event listener with following code without success
public void registerLifecycleEventObserver() {
UiThreadUtil.runOnUiThread(new Runnable() {
#Override
public void run() {
AppCompatActivity activity = (AppCompatActivity) reactContext.getCurrentActivity();
activity.getLifecycle().addObserver(KioskModeModule.this);
}
});
}
#Override
public void onStateChanged(#NonNull LifecycleOwner source, #NonNull Lifecycle.Event event) {
boolean isKioskEnabled = isLockTaskModeActive();
if (this.isKioskEnabled != isKioskEnabled) {
this.isKioskEnabled = isKioskEnabled;
WritableMap args = Arguments.createMap();
args.putBoolean("isKioskEnabled", isKioskEnabled);
sendEvent("onKioskStateChange", args);
}
}
Any idea on how i can listen to kiosk mode state change?
I finished my app with multi languages , but when the device orientation is changed to landscape then app's language is changed .
can I use (onSaveInstanceState) method to keep app language without changing when rotating screen?
what is the code I have to insert ??
Try this in your manifest
<activity
android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize">
</activity>
And then
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// you can do something here
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// orientation_landscape
Toast.makeText(this, "orientation_landscape", Toast.LENGTH_SHORT).show();
} else {
// orientation_portrait
Toast.makeText(this, "orientation_portrait", Toast.LENGTH_SHORT).show();
}
}
i put a webview in an activity .
the webview loads TelegramWeb's page.
when i login to the telegram account it works fine.
but when i rotate screen or reopen the app it forgets all data and needs relogin to telegram account.
so i need to save some data like coockies and other necessary files.
i used setJavaScriptEnabled=true and some other setting below:
#SuppressLint("SetJavaScriptEnabled") public class SubActivity extends Activity {
private WebView wv1;
protected void onSaveInstanceState(Bundle outState) {
wv1.saveState(outState);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sub);
Button b1=(Button) findViewById(R.id.btnSave);
wv1=(WebView)findViewById(R.id.webView1);
WebSettings ws=wv1.getSettings();
ws.setAllowContentAccess(true);
ws.setAppCacheEnabled(true);
ws.setSaveFormData(true);
wv1.setWebViewClient(new Webview());
wv1.getSettings().getCacheMode();
wv1.getSettings().getAllowContentAccess();
wv1.getSettings().getSaveFormData();
wv1.getSettings().setLoadsImagesAutomatically(true);
wv1.getSettings().setJavaScriptEnabled(true);
wv1.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
wv1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv1.getSettings().setAllowFileAccess(true);
wv1.getSettings().setDomStorageEnabled(true);
wv1.setSaveEnabled(true);
if (savedInstanceState != null)
wv1.restoreState(savedInstanceState);
else
wv1.loadUrl("https://web.telegram.org/#/im");
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Toast.makeText(getBaseContext(), wv1.getUrl().toString(), Toast.LENGTH_LONG).show();
}
});
}
}
but still it needs re-login to account.
better to know that SubActivity Class start from MainActivity after checking a password.
------
note:
i added this code after wf1.loadUrl and it works on screen rotation.
wv1.saveState(savedInstanceState);
but still not works when close app and reopen it. so i have to re-login.
i think i have to save the InstanceState some where.
how can i do?
If you don't want to use database for saving data you can use Shared Preferences where you save key-value pairs. More in documentation.
Try the below, it might works for cache issue,
wv1.getSettings().setDomStorageEnabled(true);
wv1.getSettings().setAppCacheEnabled(true);
The below works for device rotation and configuration changes
#Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
}
After this edit AndroidManifest.xml file like below
android:configChanges="orientation|screenSize|keyboardHidden"
I can check to see if the burn-in protection property is enabled, but is there a way to tell when burn-in mode is currently active? Like specifically when the screen shifts.
Basically something like "onAmbientModeChanged" for burn in.
Thanks!
In an activity, extend WearableActivity and override onEnterAmbientMode, you have in parameter a Bundle where you can retrieve the property wanted.
(check this WearableActivity)
#Override
public void onEnterAmbient(Bundle ambientDetails) {
super.onEnterAmbient(ambientDetails);
boolean burnIn = ambientDetails.getBoolean(EXTRA_BURN_IN_PROTECTION);
boolean lowBit = ambientDetails.getBoolean(EXTRA_LOWBIT_AMBIENT);
}
In a CanvasWatchFaceService.Engine, override onPropertiesChanged :
#Override
public void onPropertiesChanged(Bundle properties) {
super.onPropertiesChanged(properties);
boolean lowBit = properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false);
boolean burnIn = properties.getBoolean(PROPERTY_BURN_IN_PROTECTION, false);
}
Override onAmbientModeChanged(boolean inAMbientMode), it is called whenever the watchface switches from interactive to ambient mode and vice versa :
#Override
public void onAmbientModeChanged(boolean inAmbientMode) {
super.onAmbientModeChanged(inAmbientMode);
if (mState.isAmbient() != inAmbientMode) {
mState.setAmbient(inAmbientMode);
//make your updates on your drawing parameters if needed
invalidate();
}
}
I try to get the screen orientation in an Android Fragment using getResources().getConfiguration().orientation but it returns the same result even though I rotated the device in portrait and landscape mode. I also used in in onConfigurationChanged() (see code below) and the configuration received as parameter reports the corect screen orientation but the generic method of getting the screen orientation always reports the same orientation mode in which the activity started(either landscape or portrait).
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
Log.e(TAG, "NEW CONFIG: ORIENTATION_LANDSCAPE");
else
Log.e(TAG, "NEW CONFIG: ORIENTATION_PORTRAIT");
Configuration config = getResources().getConfiguration();
if(config.orientation == Configuration.ORIENTATION_PORTRAIT)
Log.e(TAG, "config: PORTRAIT");
else
Log.e(TAG, "config: LANDSCAPE");
LayoutInflater inflater = LayoutInflater.from(getActivity());
populateViewForOrientation(inflater, (ViewGroup)getView());
}
For example if the activity started in landsape mode the first log output will be:
1.a "NEW CONFIG: ORIENTATION_LANDSCAPE"
1.b "config: LANDSCAPE"
after I rotate the device in portrait mode:
2.a "NEW CONFIG: ORIENTATION_PORTRAIT"
2.b "config: LANDSCAPE"
As you can notice, the config reports the same orientation mode even though the device has different orientation mode.
So what is happening here? Thank you! :)
Some times the easy solution is not to fight the system and just to accept the facts as they are. Just update the configuration as they change.
Try this:
private Configuration configuration;
private int getOrientation(){
return getConfiguration().orientation;
}
private Configuration getConfiguration(){
if (configuration == null) {
configuration = getResources().getConfiguration();
}
return configuration;
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
configuration = newConfig;
}