Is there any way to detect if a mobile session on my android app is in android USB debugging mode or developer mode, or otherwise running automation via tools such as appium
The simplest way:
if (BuildConfig.DEBUG) {
return "debug";
}else {
return "not debug";
}
Depending on what your are doing there may be a better way, just Google Buildconfig.Degug
Related
I have a function similar to this:
private bool IsConnected()
{
if (DeviceInfo.DeviceType == DeviceType.Unknown)
return false;
var current = Connectivity.NetworkAccess;
if (current == NetworkAccess.Internet)
return true;
return false;
}
My teammates have reported zero issues with this function, and are using a variety of devices. My personal device is a Google Pixel 3, using Google Fi and Google VPN. When I cut it into airplane mode, I see Connectivity.NetworkAccess is set to NetworkAccess.None. However, when I leave airplane mode off and turn both Mobile Data and Wifi off explicitly, I see Connectivity.NetworkAccess is set to NetworkAccess.Internet.
Related to this, the Connectivity.ConnectionProfiles reports a single profile: ConnectionProfile.Unknown.
Is this expected behavior? Should I check a combination of Connectivity.ConnectionProfiles as well as Connectivity.NetworkAccess in attempting to determine if the device actually is connected to a network?
If you can't access the internet and Connectivity.NetworkAccess is NetworkAccess.Internet then it is not expected behavior.
You can submit the issue on their github: https://github.com/xamarin/Essentials/issues
We are developing a locked down "kiosk-style" Android app on a stock Samsung tablet, which is mounted in customer vehicles. We would like to be able to allow customers to edit their wifi settings, without giving them access to the rest of the Settings app (e.g. Launcher, accounts, etc)
We have been able to launch the Wifi Settings activity, but it allows the user to go into other areas.
I'm not sure whether it's possible to create a custom interface for connecting to wifi, but even if it were possible, this seems fragile and a lot of work for something quite simple.
Is there any way to solve this well?
I would create a device policy controller app that is provisioned on the device as a device owner using Android Enterprise (Android for Work) APIs.
https://developers.google.com/android/work/dpc/build-dpc
As a device owner, you can set your app in lock task mode which is generally used for kiosks.
https://developer.android.com/work/cosu.html
Then, you can set user restrictions:
addUserRestriction api
user restrictions list
The user restrictions don't cover everything in the settings app, but the coverage is pretty good.
Then I would provision it using NFC or QR code reader from the Google Setup Wizard welcome screen.
https://github.com/googlesamples/android-NfcProvisioning
You might want to also look at existing open source EMM/MDM implementations that already exist such as WSO2.
Other references:
How to enable task locking in Android 5.0 production devices
How to make sure there is only one app
I was also working on Kiosk Type applications and we have to give options for Change wifi and Display Settings So we have used these commands on Button click for Wifi And Display
Settings
btnWifiSetting.setOnClickListener {
startActivityForResult( Intent(android.provider.Settings.ACTION_WIFI_SETTINGS), 0);
}
And For Display Setting
btnDisplay.setOnClickListener {
startActivityForResult(Intent(android.provider.Settings.ACTION_DISPLAY_SETTINGS),0)
}
And you can also check the full list of Available Commands here
https://ourcodeworld.com/articles/read/318/how-to-open-android-settings-programmatically-with-java
try LineAgeOS
https://lineageos.org/
Your requirement needs to access OS System level, this way you have access and customize the WIFI settings before releasing the phone itself
can you try this way.
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
Tools_WiFi.setImageResource(R.drawable.tool_wifi_off);
} else {
wifiManager.setWifiEnabled(true);
Tools_WiFi.setImageResource(R.drawable.tool_wifi_on);
}
You can try this:
startActivityForResult(new Intent(Settings.ACTION_WIFI_SETTINGS), 0);
Hope it helps you.
I'm designing an android app, however the charging port on my phone was damaged and when I connect the computer to my phone, it says USB device not recognised. I have looked up debugging through bluetooth and wifi, however they either require a root, which needs me to connect my phone to the PC or they need that connection to set up the bluetooth/wifi debugging at first. I've been trying alternatively to use the emulator, however after fixing errors with the intel hardware acceleration, I now get a black screen whenever I launch the emulator. I would like to be able to debug on my phone, is there any workaround you can suggest that would work in this situation?
This may not be the best solution but it will let you grab logs from the device.
1. Enable the developer option on your phone if you have not done it already.
2. Enable "Bug report shortcut" or "Include bug reports in power menu" under developer options in settings. This will let you send an email with device logs attached to it.
3. Add whatever logs to your application and install it on the phone.
4. Run the app.
5. Send the logs in email using the option in power button menu.
6. Go through the logs. Go to step 3 until you fix the problem.
The .apk file may be easily transfered using Dropbox or any other filesharing service. Pick it up in the build outputs folder.
However this is not the best way to debug your app, one way of doing this would be to implement your own Log wrapper and to write your output to the file on an external storage.
A quick example would be:
public class Log {
public static int v(String tag, String msg) {
writeToLogFile(msg);
return android.util.Log.v(tag, msg);
}
public static int d(String tag, String msg) {
writeToLogFile(msg);
return android.util.Log.d(tag, msg);
}
private static void writeToLogFile(String msg){
// write to log file
}
// TODO: implement I / W / E levels logging
}
Also, how about using Fabric kit for troubleshooting.
I have an Android app I'd like to offer on the Amazon's AppStore. My app has some location-based features and camera features which I need to disable if the user's device is a Kindle. Is there a way to programmatically detect if a user's Device is a Kindle? I'm aware I can build different versions for Kindle and non-Kindle but I thought I'd first ask if there's a way to detect this in code.
To check if the device has a certain feature, you PackageManager.hasSystemFeature(String name) which should be sufficient in your case.
To check for location and camera you can use FEATURE_LOCATION and FEATURE_CAMERA as argument to hasSystemFeature
If you still need to know the hardware of your device, you can check
android.os.Build.MANUFACTURER
android.os.Build.BRAND
android.os.Build.BOARD
android.os.Build.DEVICE
If you want to detect Kindle, check for manufacturer (Amazon) using Build.MANUFACTURER and model using Build.MODEL. The value of model in case of Kindle will vary, it can be KFTT, KFOT, Kindle Fire, etc. See this for model nos.
You can use this method in identifying a Kindle Device(s)
public static boolean isKindle(){
final String AMAZON = "Amazon";
final String KINDLE_FIRE = "Kindle Fire";
return (Build.MANUFACTURER.equals(AMAZON) && Build.MODEL.equals(KINDLE_FIRE) ) || Build.MODEL.startsWith("KF");
}
I know that this post is old, but the approach to this is wrong. If your concern with Kindles is hardware related i.e. Kindles do not have a camera or camera support then you need to check for camera support not device type. What if other devices do not offer camera support? Instead of suggested answer, try this
public static boolean isCameraAvailable(Context context) {
PackageManager packageManager=context.getPackageManager();
if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
// this device has a camera
return true;
} else {
// no camera on this device
return false;
}
}
This is much better than detecting for if device is a kindle, otherwise do another build specific for kindle.
I expect that my android application is allowed to install only on real device, and android-emulator can't.How can I limit my android application installed on real device only ?
Thanks for any replies.
There's one way how to handle it. Just check device id (IMEI code). For emulator it's always null, so you can define either someone tries to launch it in real device or in emulator.
TelephonyManager tm=(TelephonyManager )activity.getSystemService(Context.TELEPHONY_SERVICE);
if(tm==null || !this.hasTelephony())
{
Log.v(TAG, "Can't get telephony service. Forcing shut down!");
return false;
}
String deviceId=tm.getDeviceId();
if(deviceId==null || deviceId.length() < 2)
{
Log.v(TAG, "Looks like emulator - bail out!");
Toast.makeText(activity, "This special version not intended to run in this device!", 5000).show();
return false;
}
Unfortunately you cannot stop people from installing in emulator, but if you have Google Licensing installed it will make sure that it does not run on unlicensed devices.