Android - How to relaunch an app in background without restarting it? - appium

I want to open an app and then navigate to settings and comeback to app and continue from the place were i left.
Tried using noReset and fullReset but nthgn worked.

You can relaunch app with using any page (Splash screen in below example) activity of Application from where you want to open app.
public static void launchActivity(Activity activityName)
{
((AndroidDriver<MobileElement>) driver).startActivity(activityName);
}
How you can call this function
Suppose you have below app package and activity (its for example but you have to use for your app)
String appPackage ="my.app.helloworld";
String appActivity = "my.app.helloworld".common.activity.SplashScreen";
launchActivity(new Activity(appPackage, appActivity));

You can use .launchApp(); to come back the previous apps and activity.
driver.launchApp();

use driver.activateApp(app_bundleId); to get back to previous state of the app.

Related

Xamarin iOS App check if GPS is enabled or prompt the user

Hi I am looking into an app which is written in Xamarin iOS. The feature I am trying to implement is
GPS must be enabled when app is running, if gps is not enabled prompt the user to enable. If the answer is yes enable the gps and continue otherwise exit app.
I am really new Xamarin and mobile development in general. After research i have found this link which shows the lifecycle of Xamarin iOS app.
Xamarin Lifecycle
The question I have is
1) Will I be able to show an alert to user from App Delegate to enable GPS when app returns from background or launched in the overrides (See link)
2) If a dialog is not possible from app delegate will it be better to create a new screen and show the dialog to enable gps instead of adding gps check in all screens.
3) Is this the correct way of checking if GPS is enabled
e.g., when app returns from background
public override void WillEnterForeground(UIApplication application)
{
Console.WriteLine("App will enter foreground");
if(CLLocationManager.Status == CLAuthorizationStatus.Denied)
{
}
}
Welcome #Abe you are on the right path!
Yes, you will be. You just have to place it in the overrides as you mentioned.
You can place the check in the AppDelegate, but it may not be the best thing to do. You might want to just place it in the Appear override of your page.
Yes using AppDelegate lifecycle overrides, is one way of checking for GPS if you need the it when your app is in the background.
Tips:
If you are using Xamarin Native, inside the ViewController, you could instead use the ViewDidLoad override to perform the check for GPS
You could instead just also just look into the Xamarin Essentials examples for a simplified way of dealing with GPS

How to detect if UIAccessibilityRequestGuidedAccessSession is active on device, iOS swift?

I know how to put app into Single app mode programmatically, provided that Autonomous single app mode persimmon is granted by MDM server to App.
This link have detail description about how to lock app in single app mode too.
Code to Apply single app mode as below -
UIAccessibilityRequestGuidedAccessSession(true){
success in
completionBlock(success)
}
My Question/Requirement is, detect if app is running in Autonomous single single app mode or UIAccessibilityRequestGuidedAccessSession is enabled, if it's enabled then only show alert to user and ask if he wish to disable Single App mode.
I Tried to detect using UIAccessibilityIsGuidedAccessEnabled() but it's of no use, as return value is always false.
You can use BOOL UIAccessibilityIsGuidedAccessEnabled(void); to get that information.
Source#AppleDocs
You could also try to add UIGuidedAccessRestrictionDelegate and then react to
func UIGuidedAccessRestrictionStateForIdentifier(_ restrictionIdentifier: String) -> UIGuidedAccessRestrictionState
Remember though, guided access needs to be enabled by the user (triple tap home button). Not from the settings!
So #Akaino answer is right, but UIAccessibilityIsGuidedAccessEnabled method wasn't working as expected due to i used to apply code below on didFinishLaunchingWithOptions hence it wasn't working properly
UIAccessibilityRequestGuidedAccessSession(true){
success in
completionBlock(success)
}
When i applied same code above on viewDidLoad() method, UIAccessibilityIsGuidedAccessEnabled is working as expected.

How to restart Android app (/app state) within Espresso test?

I'm testing login page - specifically "Autologin" checkbox, so that user being logged-in once, will be automatically logged-in upon reopening the app (by default user should login from scratch).
How can I simulate this behaviour? Is restarting an app is the only way? Can I reset an app somehow to initial screen (as if being restarted), but so that userdata/cookies should be kept?
My initial solution was to close the app by Espresso.pressBackUnconditionally() (it is similar to Espresso.pressBack() but will not throw an exception when Espresso navigates outside the application or process under test) and to launch activity again: activityRule.launchActivity(null).
However, at the end we came up with more sophisticated solution of relaunching activity within instrumentation:
with(activityRule) {
finishActivity()
launchActivity(null)
}
Activity test rule is deprecated.
You can do this using the following code in Kotlin
activityScenarioRule.scenario.close()
ActivityScenario.launch(YourActivity::class.java, null)

How can we get text while user copying message from whats up , Skype and so on like third party app using iOS Swift?

Step 01: I can run my app (APP NAME : TextDetectAPP)
Step 02: User press Home button
Step 03:User open the Skype or any third party app (APP NAME : TextDetectAPPMove to Background state )
Spep04: User copy text (I need to get copy text from Skype or or any third party app )
Note :
UIpasteboard is working fine only user developed apps in iOS swift
Shall we have access rights to read text messages from Skype , whats up or any thirds parts apps in iOS swift?
Thanks in Advance
If I understand your question right, you want to get texts that were copied in other apps (Skype, FB etc.). You can do this using the UIPasteboard class. Usually texts are copied to the general pasteboard and you can access it without any problems (I've tried with Skype and Message (iOS) applications, it is working). When you open your app back, you can get the copied text from third party apps like this in the applicationDidBecomeActive delegate method:
func applicationDidBecomeActive(_ application: UIApplication) {
if let clipboardString = UIPasteboard.general.string {
print(clipboardString)
}
}
You can also use UIPasteboardChanged notification to listen to changes in pasteboard, however you cannot receive change notifications from other apps. Also your app may not be in background state all the time executing code (unless you enable some specific background modes like Audio, Airplay etc.). So there is no way for you to get the copied texts when you are in background. You either need to use the method above, (or) if your app supports background execution, you can have an NSTimer fire every n seconds that gets the pasteboard content.

How programmatically restart an iPhone app in iOS

How programmatically restart an iPhone app in iOS?
I find this way http://writeitstudios.com/david/?p=54
But may be something simple.
The only way I know to do this is not ideal, but it works.
First, your app has to opt out of background execution (multitasking) The app has to quit when exited, not run as a background task. This is done with the plist key UIApplicationExitsOnSuspend.
Second, your app needs to register a custom URL scheme that can be used to launch the app.
Third, you need a web page hosted somewhere that when loaded will redirect to your app's custom URL scheme.
Forth, the user needs an active Internet connection.
To exit and restart, call UIApplication openURL on your hosted redirecting web page. Your app will exit and safari will launch and load your page. The page will redirect Safari to your custom URL scheme, prompting Safari to internally call openURL, causing iOS to launch your app.
my post that you linked to is referring to a Cocoa Application, not the iOS. On the iOS, you can quit an application (but Apple doesn't like this) by using exit(0); but I don't recommend that. You cannot restart iPhone apps though.
Unless you're developing for jailbroken devices, Apple won't even allow you to programatically terminate your app. So restarting the device is out of the question.
Your AppDelegate instance has a method
(void)applicationDidBecomeActive:(UIApplication *)application
{
}
In here, you can put logic to figure out if the app should restart, or continue doing whatever it was doing. For example you can have a BOOL variable appMustRestart that is false at first but gets triggered as true whenever something happens in your app that you'd like the next time to be a fresh relaunch.
if (appMustRestart)
{
[self resetVars]; // call a method that resets all your vars to initial settings
// INSERT CODE HERE TO TRANSFER FOCUS TO INITIAL VIEWCONTROLLER
}

Resources