How change VPN pop up dialog permissions? - android

How change VPN pop up dialog permissions?
I start vpn pop up dialog permission like this:
Intent intent = VpnService.prepare(this);
if (intent != null) {
VpnStatus.updateStateString("USER_VPN_PERMISSION", "",
R.string.state_user_vpn_permission,
VpnStatus.ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT);
try {
startActivityForResult(intent, START_VPN_PROFILE);
}
}
Here is the result:
Nice, but how I can change text. I want to set my custom text.
Is it possible?
And second question:
Is it possible to show message always on English. Even I change language on device?

Related

Displaying Toast after opening a Settings Activity

I'm trying to display a Toast right after I open a Settings Activity, which should contain a few instructions on what to do in the opening screen.
For example, let's say I want the user to connect to a specific network, so in my code I run
Toast.makeText(context, "Instruction message", Toast.LENGTH_SHORT).show()
startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
to display a Toast followed by a call to open up the WiFi Settings Activity. The problem here is that the Toast will display in the current Activity inside my app, but very quickly disappear as soon as the new Activity comes up.
I'm wondering if there's a way of displaying that same Toast but on the opening Activity, rather than the one that is doing the call, in order to properly instruct the user on what to do on such new Activity.
Or perhaps there's a better way of achieving this?
I think it would be better if you used a dialog, so after clicking OK, the user will be shown the screen to change WiFi, like so:
AlertDialog.Builder(context)
.setTitle("Your app name")
.setMessage("Please turn on WiFi on the following screen.")
.setPositiveButton("OK", DialogInterface.OnClickListener { dialog, id ->
{
startActivity(Settings.ACTION_WIFI_SETTINGS)
}
})
.setNegativeButton("Cancel", null)
.show();
You can read more about Dialogs here: https://developer.android.com/guide/topics/ui/dialogs

Screen Overlay Detected | (Android 6.x) Lenovo, Redmi & Samsung Devices

I have created an app which continuously run in background and show an floating overlay TextView(By using the permission android.permission.SYSTEM_ALERT_WINDOW).
I have problem in Lenovo android devices, when other applications try to request for user permission there is an alert dialog says "Screen Overlay Detected". While I have test the same application on Redmi 3S Prime device the "Allow" button in permission dialog is not clickable, until I have turned off the Floating Overlay TextView in my application.
So is there any solution to resolve this device specific issue? One of the possible solution may be disable floating TextView while permission dialog is visible to user and show floating overlay when permission dialog is closed, but the problem is how can I detect the permission dialog open/close state for other foreground application from my app.
Please suggest...
Unfortunately it seems that this is inherent to the Android OS, and as far as I know there is no way to detect when another app is requesting permissions. The general flow for interacting with other apps is to send intents to them in a push manner, so theoretically it could be done if the other apps send an intent to your app to disable the overlay, though this is not a practical solution.
I could be completely wrong, but I am yet to see a programmatic solution to this problem. The best you can probably do is warn your users that your app may cause this problem, and provide them with a quick temporary disable button.
how can I detect the permission dialog open/close state from my app??
Implement Method Mentioned Below, to run this check at the onCreate of the first Activity
public final static int PERM_REQUEST_CODE_DRAW_OVERLAYS = 1234;
/**
* Permission to draw Overlays/On Other Apps, related to
'android.permission.SYSTEM_ALERT_WINDOW'
in Manifest
Resolves issue of popup in Android M and above "Screen overlay detected- To change this permission setting you first have to turn off the screen overlay from Settings > Apps"
If app has not been granted permission to draw on the screen, create an Intent &
set its destination to
Settings.ACTION_MANAGE_OVERLAY_PERMISSION
&
* add a URI in the form of
"package:"
to send users directly to your app's page.
Note: Alternative Ignore URI to send user to the full list of apps.
public void permissionToDrawOverlays() {
if (android.os.Build.VERSION.SDK_INT >= 23) { //Android M Or Over
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, PERM_REQUEST_CODE_DRAW_OVERLAYS);
}
}
}
Called on the activity, to check on the results returned of the user action within the settings
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PERM_REQUEST_CODE_DRAW_OVERLAYS) {
if (android.os.Build.VERSION.SDK_INT >= 23) { //Android M Or Over
if (!Settings.canDrawOverlays(this)) {
// ADD UI FOR USER TO KNOW THAT UI for SYSTEM_ALERT_WINDOW permission was not granted earlier...
}
}
}
}
NOTE:Above code and extract is taken from following gist.
Hope this Helps!!!..
Just clear data of the Es explorer from device then after restart device.
I think these two links could help you.
firstlink
secondlink
Try to use for debug build -- targetSdkVersion 22.
After signed APK (for all targetSdkVersion(s)) application will work fine.

VPN Connection Trust this app dialog

I was using DNSSet app and when I opened it it showed me this dialog.
My question is what this dialog is and when accepted what it will do and how can we create one like this on our own ?
I figured it out myself. Actually this is a Android System dialog message which is called when you try to prepare a VPN connection.
Following code will make this popup visible.
Intent vi = VpnService.prepare(MainActivity.this);
if (vi != null) {
startActivityForResult(vi, 3);
}
Note that startActivityForResult is important as it will cause this popup to appear.
I was missing this line therfore it was not coming

how to call activity from inputmethodservice and get response

I have a soft keyboard as a inputmethodservice calling an activity. A button is pressed and a scanner is activated. The scanner activity captures a set of data then returns the data to the inputmethodservice for filling in a text field on a browser.
How do I return the scan value of the activity back to the inputmethodservice?
Thanks for any help.
You generally can't do this from a Service. Because a Service is not an Activity, it can not receive results from an Activity, and thus does not have startActivityForResult().
In fact you probably don't want to do this. Starting an activity is at best going to be a clunky experience -- a user doing input into a field doesn't really want to context switch out to another application's activity as part of their input.
Worse, this opens the door to a lot of ugly interactions. For example, if they press home or use a notification or recent apps to switch to another application, what will happen to your activity? Probably nothing good.
Instead I would recommend just showing a dialog as part of the IME -- use the Dialog class and set its window type to TYPE_INPUT_METHOD_DIALOG. This will display on top of your IME, allowing you to interact with the user without disrupting the editing session. For example, you'll want to set this dialog to not take input focus with FLAG_NOT_FOCUSABLE so the text editing session where the user is performing input is not disrupted.
And honestly the best thing to do is to have your UI incorporated into the IME itself.
Here is a code to test the solution using Dialog:
// 1. CREATE THE DIALOG
val builder: AlertDialog.Builder = AlertDialog.Builder(this, R.style.Theme_AppCompat_Light)
builder.setTitle("Title").setMessage("This is the message for the user. ")
val mDialog = builder.create()
// 2. SET THE IME WINDOW TOKEN ATTRIBUTE WITH THE TOKEN OF THE KEYBOARD VIEW
mDialog.window?.attributes?.token = this.mKeyboardView.windowToken
// 3. SET THE TYPE OF THE DIALOG TO TYPE_APPLICATION_ATTACHED_DIALOG
mDialog.window?.setType(WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG)
// 4. SHOW THE DIALOG
mDialog.show()
What you want is startActivityForResult(yourIntent, SCAN_VALUE). Your IME will launch the activity, which will then return a value to the IME.
So your service will do something like the following:
Intent yourIntent = new Intent(this , YourActivity.class);
this.startActivityForResult(yourIntent, SCAN_VALUE);
Also in your Service, you'll have to call onActivityResult():
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch(requestCode) {
case SCAN_VALUE:
if (resultCode == RESULT_OK) {
//TODO: Create some functionality here!
break;
}
Okay, so now let's tackle your launched activity. You'll have to modify this to fit your purposes, but here's how you would send a value back from, say, a ListAdapter. You didn't post your code, so it's tough to know exactly what you're doing.
Object o = this.getListAdapter().getItem(position);
String scanValue = o.toString();
Intent returnIntent = new Intent();
returnIntent.putExtra("ScanValue", scanValue);
setResult(RESULT_OK,returnIntent);
finish();
This will return a value to the IME launching the activity as a string. Again, if you post your code, I can give you more exact instructions. I hope this helps you wrap your mind around startActivityForResult() in the meantime, though.

How to make an activity window stay always on top

I want to create an activity that stays always on top (like the modal windows or task manager in Windows) of the others activities.
How can I do this on Android? Thanks
You can use the following code in the overridden onStop method of your activity:
#Override
protected void onStop(){
super.onStop();
Intent intent = new Intent(this, ClassNameOfYourActivity.class);
startActivity(intent);
}
Beauty problem: your activity will pop-up again if any other activity trying to claim the focus. So it's not a modal window.
And it's dangerous! You wont be able to handle the Android GUI, you'll be able to control only your application GUI. For instance, switching debug mode on-off, killing application (only over ADB), reaching system settings, etc. will be impossible. If you switch off the ADB and combine it with the auto start mechanism then you'll be in trap.
So you won't be popular if you share it with Play :)
Depending on what exactly you are trying to do, you might be happy with windows that stay on top of other Activities.
Apps like Super Video client & Floating Notes are able to display floating windows above other activities. These questions might point you in the right direction:
Creating a system overlay window (always on top)
How to create always-top fullscreen overlay activity in Android
You can't. As this is defined in the Android system.
Follow the steps to achieve your requirement
Create an activity which is going to be the top activity
Add the following code in the manifest
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Use the following code to get overlay permission from user
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
new AlertDialog.Builder(this)
.setTitle("Permission Request")
.setMessage("This app needs your permission to overlay the system apps")
.setPositiveButton("Open settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
startActivityForResult(myIntent, 101);
}
})
.setNegativeButton(android.R.string.no, null)
.show();
}
}

Categories

Resources