Highlight the Menu Item found in Search Result of Android Settings App - android

Inside Android core Settings App, when we search anything in the search bar, then the result of that search is highlighted automatically.
For e.g. please see below image where I highlighted my application name in the Notification Access section.
I achieved this by following code:
val intent = Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS").apply {
val app = "${application.packageName}/${NotificationListener::class.java.name}" //Here NotificationListener is a service name
val fragmentKey = ":settings:fragment_args_key"
val showFragmentKey = ":settings:show_fragment_args"
putExtra(fragmentKey, app)
putExtra(showFragmentKey, Bundle().apply { putString(fragmentKey, app) })
}
I referred to the Solution on this LINK
However, I want to highlight my application name in the Usage Access Setting.
i.e. when I open the intent for Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS) then inside the list of apps, my app name must be highlighted.
However the above logic/approach is not working for Usage Access Screen.
My application opens the intent but does not highlight my app name there.
I did a detailed research but I am still facing challenge.
Hence, I request you all to please assist.

For ACTION_USAGE_ACCESS_SETTINGS , I can't find one. Have you seen it anywhere? If so, please show me on which app. I've requested about this here:
https://issuetracker.google.com/issues/165311852
https://issuetracker.google.com/issues/160303945
And one in general, for all settings:
https://issuetracker.google.com/issues/163176781
As for notification-access, check here: stackoverflow.com/a/63914445/878126

Related

How can you create a Deeplink using placeholders and nav component at build time

We have an app that utilises Deeplinks. We also use the Android Navigation component.
Currently we configure our Deeplinks in out navigation.xml file and this works fine but we now have the requirement to be able to add another Deeplink at build time based on a set Environment Variable.
I have attempted setting String resources in the build.gradle and referenceing these in the navigation.xml.
I have also attempted setting a placeholder in the navigation.xml but cannot replace it as it has already been parsed as a URI.
I have also attempted setting direct intent filters in the Manifest with placeholders, this will work but we lose the nice routing from the navigation component.
Currently we configure our Deeplinks in out navigation.xml file in the following form:
<deepLink
android:autoVerify="true"
app:uri="foo.bar.baz/pull/{quxArg}/{quuxArg}" />
We now have the requirement to be able to create an additional Deeplink at build time based on a set Envar.
Example:
DEEPLINK_ENVAR = "replacement.com"
Build.gradle:
manifestPlaceholders = [deeplink:DEEPLINK_ENVAR]
navigation.xml:
<deepLink
android:autoVerify="true"
app:uri="${deeplink}/pull/{quxArg}/{quuxArg}" />
Please note the above does not work.
If this was just an intent-filter in the Manifest we could use Manifest placeholders to achieve this task and set them in the app.gradle. However Deeplinks set in navigation.xml are parsed as URIs and destroy any placeholders before they can be replaced.
Has anyone attempted anything similar? I am trying to avoid having to run a pre-build script to template the navigation file directly.
Desired outcome:
I am looking to be able to add an additional deeplink (4 actually to different destinations) at build time whilst making use of Android Navigation component.
Not sure if I completely understand but...
You should be able to add several deepLinks to a single action.
If you require it to redirect to a different fragment, you could try have a "deepLinkTokenCheckFragment" or something, which receives the deepLink, then extracts the information from it, and can redirect the user to the page that you want them to go to.
I have an application that does something like this
private fun extractAction() {
if (ACTION_VIEW == parent.intent.action) {
// Collect information to know where to redirect here.....
val actionType = parent.intent.data
?.toString()
?.substringBefore('?')
?.substringAfterLast('/')
action = get information or token from the url here //?.substringBefore('?') ?.substringAfterLast('/')
when (action) {
"change_password" -> go to change password screen
"change email" -> go to change email screen
"go to other" -> go to other screen
}
}
}
This is just an idea of how I did it.
In the same way, instead of checking some token, you could check the build or whatever you need to compare it to.
NavDestination:
public final void addDeepLink (String uriPattern)
Add a deep link to this destination. Matching Uris sent to NavController.handleDeepLink(Intent) or NavController.navigate(Uri) will trigger navigating to this destination.
https://developer.android.com/reference/androidx/navigation/NavDestination.html#addDeepLink(java.lang.String)
This sounds like it could help you.
I have not tested it myself.

Android Expresso/UI Automator How do i automate clicking on Android screens outside my app (app picker)

My Android application has a button to download a file and then send it to an application on the device. Android pops up a screen listing the Applications on the device for the user to select which application to use.
I would like to automate this flow but i can not see how I can automate clicking on the Application Picker that Android presents. I presume this is because it is outside of my application.
I tried using Android Studio's "Record Expresso Test", I performed the following test steps
click on the action which sends my image to an app on the device (action1)
saw the Android Application picker appear and chose photos
Clicked back to close photos app and go back to my app
click on a different action in my app (action2)
I see in the recorded test code for steps 1 and 4 above, but nothing for 2 and 3. Therefore it makes me think that Expresso can not be used for this particular test flow.
Does anyone know how I could test this flow using Expresso?
EDIT:
Thank you to "John O'Reilly" for recommending UI Automator. I can see that I can use the UI Automator code within my Expresso test successfully. However I am having trouble writing a precise verification of the Application Selector.
The selector will have a title of "Open With". Using Android Device Monitor I can see the hierarchy of objects as illustrated below.
Some classes and IDs are internal so I can not search on those things. I do not want to code to look for a specific application as when the test is run on another machine it may not have that application. I just need to verify that the application picker has been displayed.
// the app selector has a FrameLayout as one of its parent views, and a child Text View which has the "Open With" title
UiObject labelOnly = new UiObject(new UiSelector()
.className("android.widget.FrameLayout")
.childSelector(new UiSelector()
.className("android.widget.TextView")
.text(openWithLabel)
)
);
boolean labelOnly_exists = labelOnly.exists();
// the app selector has a FrameLayout as one of its parent views, and a child ListView (containing the apps)
UiObject listOnly = new UiObject(new UiSelector()
.className("android.widget.FrameLayout")
.childSelector(new UiSelector()
.className("android.widget.ListView")
)
);
boolean listOnly_exists = listOnly.exists();
// I can use the listView to search for a specific app, but this makes the tests fragile if a different device does not have that app installed
UiObject listAndAppName = new UiObject(new UiSelector()
.className("android.widget.ListView")
.instance(0)
.childSelector(new UiSelector()
.text("Photos")));
boolean listAndAppName_exists = listAndAppName.exists();
How could i write a statement that verifies that what is on the screen is the application picker? I was hoping maybe have a selector that searches for a FrameLayout which has a child textView containing "Open With" and also contains a child ListView. With these 2 checks together it should identify only the application picker.
The credit for the answer to this question should go to John O'Reilly who pointed me to use the UI Automator.
I resolved the issue of checking what Android screen is invoked when my test clicks on an action by just checking there is a TextView on the screen with the title I am expecting. Its not perfect as this will pass if there is any TextView on the screen with the text so does not precisely check its the application picker.
However, for my test this should be enough of a check as my app (which would be behind the app picker) should not have a TextView with the expected title, so if the title is found its pretty much likely to be the application picker.
public static boolean verifyAndroidScreenTitlePresent(String title) {
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiObject titleTextUI = new UiObject(new UiSelector()
.className("android.widget.TextView")
.text(title)
);
boolean titleExists = titleTextUI.exists();
// close the app selector to go back to our app so we can carry on with Expresso
mDevice.pressBack();
return titleExists;
}

Open a website inside app using corona

I want the user to open website / web page inside app and not in browser. I have a button, which should open a webpage on click.
I am using native.showWebPopup function for this in main.lua. The problem that I am getting is, a white colored page flashes and disappears immediately.
Below is my code. Any help is greatly appreciated. Thanks.
function openLink(event)
if(event.phase == "ended")then
native.showWebPopup("http://www.google.co.in")
end
end
btn:addEventListener("touch", openLink)
Make sure you check that you've provided access to the internet on Android!
Referring to the documentation: http://docs.coronalabs.com/api/library/native/showWebPopup.html
For Android
If the web popup is displaying web pages from the Internet, you must add the INTERNET permission to the build.settings file.
settings =
{
android =
{
usesPermissions =
{
"android.permission.INTERNET",
},
},
}
Other than that, the syntax looks correct, so I suspect it is a permissions problem.
Hope that helps!

Android Facebook SDK - action.setPlace Error in Custom Stories in Andorid(Feed Dialog Method)

I am trying to post a FB Custom story in Android using Open Graph(Share Dialog Method). The code was working very well and posted successfully, until I had added action.setPlace(). Now the Share dialog is appearing correctly. But when I click the 'POST' button, a wierd error message comes as follows
"We are Sorry, this post is no longer available. It may have been removed"
And in onActivityResult(), I get the following exception "com.facebook.FacebookException: Error publishing message"
Here is my code
OpenGraphObject place = OpenGraphObject.Factory
.createForPost("shellstationstunisia:shell_gas_station");
place.setProperty("title", "Shell Stations Tunisia");
place.setProperty(
"image",
"http://img1.wikia.nocookie.net/__cb20070306105202/uncyclopedia/images/4/4e/Shell_Logo.png");
place.setProperty(
"url",
"http://www.shell.com/global/aboutshell/contact-us/contact/contact-tunisia.html");
place.setProperty("description", "Best Gas Station in Tunisia");
OpenGraphAction action = GraphObject.Factory
.create(OpenGraphAction.class);
action.setProperty("shell_gas_station", place);
//Set a Place - THIS CAUSED THE PROBLEM - Place ID is correct
GraphPlace my_current_location = GraphObject.Factory
.create(GraphPlace.class);
my_current_location.setId("432170683497784");
action.setPlace(my_current_location);
#SuppressWarnings("deprecation")
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(
this, action, "shellstationstunisia:travel",
"shell_gas_station").build();
uiHelper.trackPendingDialogCall(shareDialog.present());
I solved the problem by myself. It was an Authentication issue. I had to enable 'Place' Capabilites from FB Developer Panel. Just follow the steps given below,
In developers.facebook.com, open your app dashboard.
In the Left pane, open 'Open Graph.
Select 'Action Types' tab
Select the Action type for which your getting the above mentioned error.
Scroll down to the section and you will find 'Capabilities' Section
Turn ON 'Place' or any other capability which you would like to use
Click Save Changes.
Now your app would work fine :)
I solve this problem by this way:
Open your "Settings" - "Display Name"
Change "Display Name" into your app name (must be the same)
Hope this can help you!

Recent Apps on UiAutomator

I am now working with Android UiAutomator on for UI Test on my Android app. My app has a function that requires the user to verify the email to continue, so I try to do it like this: after reach to that function -> getUiDevice.pressHome -> Browser -> try to log in email -> PressHome again -> Press RecentApps then I stuck here, I cannot press on my Apps to return to it again. I try another way by clicking on my App icon but it starts my app again, not at the state before. Can anyone suggest me a solution for this? Any help is appreciate.
Thanks in advance.
Try this :
UiObject appBackground = new UiObject(new UiSelector().description("ABC"));
appBackground.click();
It did not show any description through 'uiautomatorviewer' command but this worked for me.
I could manage to create this behavior with:
fun backgroundAndForeground() {
val device = UiDevice.getInstance(getInstrumentation())
device.pressHome()
// Pressing app switch two times makes the last app put on background come to foreground.
device.pressKeyCode(KeyEvent.KEYCODE_APP_SWITCH)
device.pressKeyCode(KeyEvent.KEYCODE_APP_SWITCH)
}
In this case, I think that android only resume app when clicking the recent app image. It does not work on clicking display text or app icon. So, we need to click image of your app in recent app list. At that time you need to write as below. I always do that for similar case.
// Take all image view by class type and click by instance no.
new UiObject(new UiSelector().className("android.widget.ImageView").instance(3)).click();
You need to count instance no of your recent app image view. Not app icon image in recent app scroll view. Please try this. Thanks.
I've spent half a day on this and concluded I needed to issue a device.click(). Since my use-case is that my app was the last one running (not switching to the browser like you), I can safely click the middle of the screen and it'll always work.
If you're the 2nd to last running app, you can probably do x: 0 and y: device.displayHeight/2.
I've not tested this on many operating systems, only 9.

Categories

Resources