├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── build.gradle ├── deviceutils ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── robj │ │ └── deviceutils │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── robj │ │ │ └── deviceutils │ │ │ ├── AppUtils.java │ │ │ ├── BaseDevice.java │ │ │ ├── BluetoothUtils.java │ │ │ ├── ContactUtils.java │ │ │ ├── ImageUtils.java │ │ │ ├── Optional.java │ │ │ ├── PermissionsUtil.java │ │ │ └── WifiUtils.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── com │ └── robj │ └── deviceutils │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | maven { 7 | url 'https://maven.google.com/' 8 | name 'Google' 9 | } 10 | } 11 | dependencies { 12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line 13 | classpath 'com.android.tools.build:gradle:3.0.0' 14 | classpath 'me.tatarka:gradle-retrolambda:3.7.0' 15 | // NOTE: Do not place your application dependencies here; they belong 16 | // in the individual module build.gradle files 17 | } 18 | } 19 | 20 | allprojects { 21 | repositories { 22 | jcenter() 23 | maven { 24 | url 'https://maven.google.com/' 25 | name 'Google' 26 | } 27 | } 28 | } 29 | 30 | task clean(type: Delete) { 31 | delete rootProject.buildDir 32 | } 33 | -------------------------------------------------------------------------------- /deviceutils/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /deviceutils/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | 5 | compileSdkVersion 27 6 | 7 | defaultConfig { 8 | minSdkVersion 16 9 | targetSdkVersion 27 10 | versionCode 1 11 | versionName "0.5" 12 | 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | 15 | } 16 | 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | compileOptions { 24 | sourceCompatibility JavaVersion.VERSION_1_8 25 | targetCompatibility JavaVersion.VERSION_1_8 26 | } 27 | } 28 | ext { 29 | rxJava = '2.1.0' 30 | } 31 | dependencies { 32 | implementation fileTree(dir: 'libs', include: ['*.jar']) 33 | 34 | implementation 'com.android.support:appcompat-v7:27.0.2' 35 | compile "io.reactivex.rxjava2:rxjava:$rxJava" 36 | compile "io.reactivex.rxjava2:rxandroid:2.0.1" 37 | } 38 | -------------------------------------------------------------------------------- /deviceutils/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /deviceutils/src/androidTest/java/com/robj/deviceutils/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.robj.deviceutils.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /deviceutils/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /deviceutils/src/main/java/com/robj/deviceutils/AppUtils.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.pm.ApplicationInfo; 6 | import android.content.pm.PackageManager; 7 | import android.content.pm.ResolveInfo; 8 | import android.graphics.Bitmap; 9 | import android.graphics.Canvas; 10 | import android.graphics.drawable.Drawable; 11 | import android.util.Log; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | import io.reactivex.Observable; 17 | 18 | public class AppUtils { 19 | 20 | private static final String TAG = AppUtils.class.getSimpleName(); 21 | 22 | public static final String ALL = "ALL"; 23 | 24 | public static Observable> getInstalledApps(Context context) { 25 | return Observable.create(e -> { 26 | Log.d(TAG, "Retrieving installed apps.."); 27 | Intent i = new Intent("android.intent.action.MAIN"); 28 | i.addCategory("android.intent.category.LAUNCHER"); 29 | List list = context.getPackageManager().queryIntentActivities(i, PackageManager.GET_META_DATA); 30 | ArrayList apps = new ArrayList(); 31 | if (list != null && list.size() > 0) { 32 | for (ResolveInfo packageInfo : list) { 33 | App tmp = new App(packageInfo.activityInfo.packageName, packageInfo.loadLabel(context.getPackageManager()).toString()); 34 | apps.add(tmp); 35 | } 36 | } 37 | e.onNext(apps); 38 | }); 39 | } 40 | 41 | public static Bitmap getAppIcon(Context context, String packageName, int size) { 42 | try { 43 | Drawable d = context.getPackageManager().getApplicationIcon(packageName); 44 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); 45 | Canvas canvas = new Canvas(bitmap); 46 | d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); 47 | d.draw(canvas); 48 | return bitmap; 49 | } catch (Exception e) { 50 | e.printStackTrace(); 51 | Log.e(TAG, "No icon found.."); 52 | return null; 53 | } 54 | } 55 | 56 | public static String getAppLabel(Context context, String packageName) { 57 | try { 58 | ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(packageName, 0); 59 | if (appInfo != null) 60 | return appInfo.loadLabel(context.getPackageManager()).toString(); 61 | } catch (Exception e) { 62 | e.printStackTrace(); 63 | } 64 | return null; //Unknown 65 | } 66 | 67 | public static class App { 68 | public final String packageName; 69 | public final String displayName; 70 | public App(String packageName, String displayName) { 71 | this.packageName = packageName; 72 | this.displayName = displayName; 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /deviceutils/src/main/java/com/robj/deviceutils/BaseDevice.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | /** 4 | * Created by jj on 15/02/18. 5 | */ 6 | 7 | abstract class BaseDevice { 8 | 9 | private final String uniqueIdentifier; 10 | private final String name; 11 | 12 | protected BaseDevice(String uniqueIdentifier, String name) { 13 | this.uniqueIdentifier = uniqueIdentifier; 14 | this.name = name; 15 | } 16 | 17 | public String getUniqueIdentifier() { 18 | return uniqueIdentifier; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /deviceutils/src/main/java/com/robj/deviceutils/BluetoothUtils.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | import android.Manifest; 4 | import android.annotation.SuppressLint; 5 | import android.bluetooth.BluetoothAdapter; 6 | import android.bluetooth.BluetoothDevice; 7 | import android.bluetooth.BluetoothManager; 8 | import android.bluetooth.BluetoothProfile; 9 | import android.content.Context; 10 | import android.net.wifi.WifiConfiguration; 11 | import android.os.Build; 12 | import android.text.TextUtils; 13 | import android.util.Log; 14 | 15 | import java.lang.reflect.InvocationTargetException; 16 | import java.lang.reflect.Method; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | import java.util.Set; 20 | 21 | import io.reactivex.Observable; 22 | 23 | /** 24 | * Created by Rob J on 15/06/17. 25 | */ 26 | 27 | public class BluetoothUtils { 28 | 29 | @SuppressLint("MissingPermission") 30 | public static Observable> getPairedDevices(Context context) { 31 | return Observable.create(subscriber -> { 32 | if(PermissionsUtil.hasPermission(context, Manifest.permission.BLUETOOTH)) { 33 | BluetoothAdapter mBluetoothAdapter = getDefaultAdapter(context); 34 | if(mBluetoothAdapter == null) { 35 | if(subscriber != null && !subscriber.isDisposed()) { 36 | subscriber.onError(new RuntimeException("Bluetooth is not supported on this device")); 37 | subscriber.onComplete(); 38 | } 39 | return; 40 | } 41 | Set pairedDevices = mBluetoothAdapter.getBondedDevices(); 42 | List devices = new ArrayList(); 43 | if (pairedDevices.size() > 0) 44 | for (BluetoothDevice bt : pairedDevices) { 45 | Device device = new Device(bt); 46 | devices.add(device); 47 | } 48 | if(subscriber != null && !subscriber.isDisposed()) { 49 | subscriber.onNext(devices); 50 | subscriber.onComplete(); 51 | } 52 | } else { 53 | if(subscriber != null && !subscriber.isDisposed()) { 54 | subscriber.onError(new RuntimeException("Bluetooth permission is missing")); 55 | subscriber.onComplete(); 56 | } 57 | } 58 | }); 59 | } 60 | 61 | private static BluetoothAdapter getDefaultAdapter(Context context) { 62 | BluetoothAdapter bluetoothAdapter; 63 | if(Build.VERSION.SDK_INT >= 18) { 64 | BluetoothManager bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE); 65 | bluetoothAdapter = bluetoothManager.getAdapter(); 66 | } else 67 | bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 68 | if(bluetoothAdapter == null) 69 | Log.d(BluetoothUtils.class.getSimpleName(), "Bluetooth is not supported on this device, no adapter found.."); 70 | return bluetoothAdapter; 71 | } 72 | 73 | @SuppressLint("MissingPermission") 74 | public static String getDeviceAliasName(Context context, String btAddress) { 75 | BluetoothAdapter mBluetoothAdapter = getDefaultAdapter(context); 76 | BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(btAddress); 77 | String deviceAlias = null; 78 | if(device != null) 79 | try { 80 | Method method = device.getClass().getMethod("getAliasName"); 81 | if(method != null) 82 | deviceAlias = (String) method.invoke(device); 83 | } catch (NoSuchMethodException e) { 84 | e.printStackTrace(); 85 | } catch (InvocationTargetException e) { 86 | e.printStackTrace(); 87 | } catch (IllegalAccessException e) { 88 | e.printStackTrace(); 89 | } 90 | if(TextUtils.isEmpty(deviceAlias)) 91 | return device.getName(); 92 | else 93 | return deviceAlias; 94 | } 95 | 96 | public static boolean isBluetoothSupported(Context context) { 97 | return getDefaultAdapter(context) != null; 98 | } 99 | 100 | public static boolean isBluetoothAvailable(Context context) { 101 | final BluetoothAdapter bluetoothAdapter = getDefaultAdapter(context); 102 | return (bluetoothAdapter != null && bluetoothAdapter.isEnabled()); 103 | } 104 | 105 | public static void getConnectedBluetoothDevice(Context context, OnBluetoothConnection onBluetoothConnection) { 106 | getConnectedBluetoothDevice(context, onBluetoothConnection, BluetoothProfile.A2DP); 107 | } 108 | 109 | private static void getConnectedBluetoothDevice(Context context, final OnBluetoothConnection onBluetoothConnection, int profileType) { 110 | if (isBluetoothAvailable(context)) { 111 | BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() { 112 | public void onServiceConnected(int profileType_, BluetoothProfile proxy) { 113 | if (profileType_ == profileType) { 114 | List connectedDevices = proxy.getConnectedDevices(); 115 | for (BluetoothDevice device : connectedDevices) { 116 | if(device == null || device.getAddress() == null) 117 | continue; 118 | onBluetoothConnection.onConnected(device); 119 | return; 120 | } 121 | if (profileType != BluetoothProfile.HEADSET) 122 | getConnectedBluetoothDevice(context, onBluetoothConnection, BluetoothProfile.HEADSET); 123 | else 124 | onBluetoothConnection.onNoConnection(); 125 | getDefaultAdapter(context).closeProfileProxy(profileType, proxy); 126 | } 127 | } 128 | 129 | public void onServiceDisconnected(int profile) { 130 | onBluetoothConnection.onNoConnection(); 131 | } 132 | }; 133 | BluetoothAdapter.getDefaultAdapter().getProfileProxy(context, mProfileListener, profileType); 134 | } else 135 | onBluetoothConnection.onNoConnection(); 136 | } 137 | 138 | public static Observable> getConnectedBluetoothDevice(Context context) { 139 | return Observable.create(subscriber -> { 140 | getConnectedBluetoothDevice(context, new OnBluetoothConnection() { 141 | @Override 142 | public void onConnected(BluetoothDevice device) { 143 | if(subscriber != null && !subscriber.isDisposed()) { 144 | subscriber.onNext(new Optional(device)); 145 | subscriber.onComplete(); 146 | } 147 | } 148 | @Override 149 | public void onNoConnection() { 150 | if(subscriber != null && !subscriber.isDisposed()) { 151 | subscriber.onNext(new Optional(null)); 152 | subscriber.onComplete(); 153 | } 154 | } 155 | }); 156 | }); 157 | } 158 | 159 | public static class Device extends BaseDevice { 160 | 161 | public Device(BluetoothDevice bt) { 162 | super(bt.getAddress(), bt.getName()); 163 | } 164 | 165 | } 166 | 167 | public interface OnBluetoothConnection { 168 | void onConnected(BluetoothDevice profile); 169 | void onNoConnection(); 170 | } 171 | 172 | public static class NoBluetoothConnectedException extends Throwable { } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /deviceutils/src/main/java/com/robj/deviceutils/ContactUtils.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | import android.Manifest; 4 | import android.content.ContentUris; 5 | import android.content.Context; 6 | import android.database.Cursor; 7 | import android.graphics.Bitmap; 8 | import android.net.Uri; 9 | import android.provider.ContactsContract; 10 | import android.provider.ContactsContract.PhoneLookup; 11 | import android.text.TextUtils; 12 | import android.util.Log; 13 | 14 | import java.io.InputStream; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | import io.reactivex.Observable; 19 | import io.reactivex.ObservableOnSubscribe; 20 | import io.reactivex.schedulers.Schedulers; 21 | 22 | 23 | /** 24 | * Created by Rob J on 05/08/15. 25 | */ 26 | public class ContactUtils { 27 | 28 | private static final String TAG = ContactUtils.class.getSimpleName(); 29 | 30 | public static Contact getContact(Context context, String[] people) { 31 | Contact contact = null; 32 | if (people != null && people.length == 1) { //TODO: Don't know how to handle multiple?? 33 | int size = people.length; 34 | if (PermissionsUtil.hasPermission(context, Manifest.permission.READ_CONTACTS)) { 35 | StringBuilder sb = new StringBuilder(); 36 | for (int i = 0; i < size; i++) { 37 | sb.append(people[i]); 38 | sb.append(", "); 39 | sb.append(ContactUtils.getContactByUri(context, people[i])); 40 | contact = ContactUtils.getContactByUri(context, people[i]); 41 | if(contact != null) 42 | Log.d(ContactUtils.class.getSimpleName(), "People: " + contact.displayName); 43 | } 44 | } 45 | } 46 | return contact; 47 | } 48 | 49 | public static Contact getContact(Context context, String number) { 50 | Contact contact = new Contact(-1, number); 51 | if(!TextUtils.isEmpty(number)) { 52 | if(PermissionsUtil.hasPermission(context, Manifest.permission.READ_CONTACTS)) { 53 | Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); 54 | Cursor c = context.getContentResolver().query(uri, 55 | new String[]{PhoneLookup.LOOKUP_KEY, PhoneLookup.DISPLAY_NAME, PhoneLookup._ID}, 56 | null, null, null); 57 | if(c != null) { 58 | if (c.moveToFirst()) { 59 | long id = c.getLong(c.getColumnIndexOrThrow(PhoneLookup._ID)); 60 | String displayName = c.getString(c.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME)); 61 | contact = new Contact(id, displayName, getPhoneNumbers(context, id)); 62 | } 63 | c.close(); 64 | } 65 | } else 66 | Log.d(TAG, "Couldn't retrieve contact, permission READ_CONTACTS not granted.."); 67 | } 68 | 69 | return contact; 70 | } 71 | 72 | public static String getNameFromNumber(Context context, String number) { 73 | String name = null; 74 | if(!TextUtils.isEmpty(number)) { 75 | if(PermissionsUtil.hasPermission(context, Manifest.permission.READ_CONTACTS)) { 76 | Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); 77 | Cursor c = context.getContentResolver().query(uri, 78 | new String[]{PhoneLookup.LOOKUP_KEY, PhoneLookup.DISPLAY_NAME, PhoneLookup._ID}, 79 | null, null, null); 80 | if(c != null) { 81 | if (c.moveToFirst()) 82 | name = c.getString(c.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME)); 83 | c.close(); 84 | } 85 | } else 86 | Log.d(TAG, "Couldn't retrieve contact, permission READ_CONTACTS not granted.."); 87 | } 88 | return name; 89 | } 90 | 91 | public static Contact getContactByUri(Context context, String uri) { 92 | Contact contact = null; 93 | String[] projection = new String[] { 94 | ContactsContract.Contacts._ID, 95 | ContactsContract.Contacts.DISPLAY_NAME, 96 | ContactsContract.Contacts.NAME_RAW_CONTACT_ID 97 | }; 98 | Cursor cursor = context.getContentResolver().query ( 99 | Uri.parse(uri), 100 | projection, 101 | null, 102 | null, 103 | null); 104 | if(cursor != null) { 105 | int nameColIndex = cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME); 106 | int idColIndex = cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID); 107 | if (cursor.moveToNext()) { 108 | long contactId = cursor.getLong(idColIndex); 109 | String displayName = cursor.getString(nameColIndex); 110 | contact = new Contact(contactId, displayName, getPhoneNumbers(context, contactId)); 111 | } 112 | cursor.close(); 113 | } 114 | return contact; 115 | } 116 | 117 | 118 | public static Contact getContactById(Context context, long id) { 119 | Contact contact = null; 120 | if(id > -1) { 121 | if (PermissionsUtil.hasPermission(context, Manifest.permission.READ_CONTACTS)) { 122 | Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; 123 | Cursor c = context.getContentResolver().query(uri, 124 | new String[]{ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME}, 125 | ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{String.valueOf(id)}, null); 126 | if (c != null) { 127 | int idColIndex = c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.CONTACT_ID); 128 | int nameColIndex = c.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME); 129 | while (c.moveToNext()) { 130 | long contactId = c.getLong(idColIndex); 131 | String displayName = c.getString(nameColIndex); 132 | contact = new Contact(contactId, displayName, getPhoneNumbers(context, contactId)); 133 | } 134 | c.close(); 135 | } 136 | } else 137 | Log.d(TAG, "Couldn't retrieve contact, permission READ_CONTACTS not granted.."); 138 | } 139 | return contact; 140 | } 141 | 142 | public static String getNameById(Context context, long id) { 143 | String name = null; 144 | if(id > -1) { 145 | if (PermissionsUtil.hasPermission(context, Manifest.permission.READ_CONTACTS)) { 146 | Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; 147 | Cursor c = context.getContentResolver().query(uri, 148 | new String[]{ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME}, 149 | ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{String.valueOf(id)}, null); 150 | if (c != null) { 151 | int nameColIndex = c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME); 152 | while (c.moveToNext()) 153 | name = c.getString(nameColIndex); 154 | c.close(); 155 | } 156 | } else 157 | Log.d(TAG, "Couldn't retrieve contact, permission READ_CONTACTS not granted.."); 158 | } 159 | return name; 160 | } 161 | 162 | public static Observable> getContactsObservable(Context context, boolean withNumbers) { 163 | return Observable.create((ObservableOnSubscribe>) e -> { 164 | try { 165 | if(!PermissionsUtil.hasPermission(context, Manifest.permission.READ_CONTACTS)) 166 | throw new PermissionsUtil.PermissionException(Manifest.permission.READ_CONTACTS); 167 | List contacts = new ArrayList(); 168 | Cursor cur = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 169 | new String[]{ContactsContract.CommonDataKinds.Phone.CONTACT_ID, PhoneLookup.DISPLAY_NAME}, 170 | null, null, PhoneLookup.DISPLAY_NAME); 171 | if (cur != null) { 172 | try { 173 | int idColIndex = cur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.CONTACT_ID); 174 | int nameColIndex = cur.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME); 175 | while (cur.moveToNext()) { 176 | long contactId = cur.getLong(idColIndex); 177 | String displayName = cur.getString(nameColIndex); 178 | Contact tmp = withNumbers ? new Contact(contactId, displayName, getPhoneNumbers(context, contactId)) : new Contact(contactId, displayName); 179 | contacts.add(tmp); 180 | } 181 | } finally { 182 | cur.close(); 183 | } 184 | } 185 | e.onNext(contacts); 186 | } catch (Exception ex) { 187 | ex.printStackTrace(); 188 | e.onError(ex); 189 | } 190 | }).subscribeOn(Schedulers.io()); 191 | } 192 | 193 | public static Contact getContactByName(Context context, String name) { 194 | Contact contact = null; 195 | if(!TextUtils.isEmpty(name)) { 196 | if (PermissionsUtil.hasPermission(context, Manifest.permission.READ_CONTACTS)) { 197 | Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI; 198 | Cursor c = context.getContentResolver().query(uri, new String[]{ ContactsContract.CommonDataKinds.Phone.CONTACT_ID, PhoneLookup.DISPLAY_NAME }, 199 | ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " = ?", new String[]{ name }, null); 200 | if (c != null) { 201 | int idColIndex = c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.CONTACT_ID); 202 | int nameColIndex = c.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME); 203 | while (c.moveToNext()) { 204 | long contactId = c.getLong(idColIndex); 205 | String displayName = c.getString(nameColIndex); 206 | contact = new Contact(contactId, displayName, getPhoneNumbers(context, contactId)); 207 | } 208 | c.close(); 209 | } 210 | } else 211 | Log.d(TAG, "Couldn't retrieve contact, permission READ_CONTACTS not granted.."); 212 | } 213 | return contact; 214 | } 215 | 216 | public static List getPhoneNumbers(Context context, long contactId) { 217 | Cursor c = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, 218 | ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null); 219 | List numbers = new ArrayList(); 220 | if (c != null) { 221 | int numColIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER); 222 | int typeColIndex = c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE); 223 | while (c.moveToNext()) { 224 | String number = c.getString(numColIndex); 225 | int type = c.getInt(typeColIndex); 226 | numbers.add(new Number(number, type)); 227 | } 228 | c.close(); 229 | } 230 | return numbers; 231 | } 232 | 233 | public static Bitmap getAvatar(Context context, long contactId, boolean preferHigherRes) { 234 | Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId); 235 | InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), uri, preferHigherRes); 236 | if (input != null) 237 | return ImageUtils.decodeStream(input); 238 | return null; 239 | } 240 | 241 | public static class Contact { 242 | public final long contactId; 243 | public final String displayName; 244 | public final List numbers = new ArrayList(); 245 | public Contact(long contactId, String displayName) { 246 | this.contactId = contactId; 247 | this.displayName = displayName; 248 | } 249 | public Contact(long contactId, String displayName, List numbers) { 250 | this.contactId = contactId; 251 | this.displayName = displayName; 252 | this.numbers.addAll(numbers); 253 | } 254 | } 255 | public static class Number { 256 | public final String number; 257 | public final int type; 258 | public Number(String number, int type) { 259 | this.number = number; 260 | this.type = type; 261 | } 262 | } 263 | 264 | } 265 | -------------------------------------------------------------------------------- /deviceutils/src/main/java/com/robj/deviceutils/ImageUtils.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapFactory; 5 | 6 | import java.io.ByteArrayOutputStream; 7 | import java.io.InputStream; 8 | 9 | /** 10 | * Created by Rob J on 24/06/17. 11 | */ 12 | 13 | public class ImageUtils { 14 | 15 | public static Bitmap decodeStream(InputStream input) { 16 | return BitmapFactory.decodeStream(input); 17 | } 18 | 19 | public static byte[] bitmapToByteArray(Bitmap bitmap) { 20 | ByteArrayOutputStream stream = new ByteArrayOutputStream(); 21 | bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); 22 | return stream.toByteArray(); 23 | } 24 | 25 | public static Bitmap byteArrayToBitmap(byte[] array, int maxWidth, int maxHeight) { 26 | BitmapFactory.Options options = new BitmapFactory.Options(); 27 | options.inJustDecodeBounds = true; 28 | Bitmap bmp = BitmapFactory.decodeByteArray(array, 0, array.length, options); 29 | options.inSampleSize = calculateInSampleSize(options, maxWidth, maxHeight); 30 | options.inJustDecodeBounds = false; 31 | if(bmp != null) 32 | bmp.recycle(); 33 | return BitmapFactory.decodeByteArray(array, 0, array.length, options); 34 | } 35 | 36 | private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { 37 | final int height = options.outHeight; 38 | final int width = options.outWidth; 39 | int inSampleSize = 1; 40 | 41 | if (height > reqHeight || width > reqWidth) { 42 | 43 | final int halfHeight = height / 2; 44 | final int halfWidth = width / 2; 45 | 46 | while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) 47 | inSampleSize *= 2; 48 | } 49 | 50 | return inSampleSize; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /deviceutils/src/main/java/com/robj/deviceutils/Optional.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | import java.util.NoSuchElementException; 4 | 5 | import io.reactivex.annotations.Nullable; 6 | 7 | /** 8 | * Created by Rob J on 21/09/17. 9 | */ 10 | 11 | public class Optional { 12 | 13 | private final T optional; 14 | 15 | public Optional(@Nullable T optional) { 16 | this.optional = optional; 17 | } 18 | 19 | public boolean isEmpty() { 20 | return this.optional == null; 21 | } 22 | 23 | public T get() { 24 | if (optional == null) 25 | throw new NoSuchElementException("Item was null.."); 26 | return optional; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /deviceutils/src/main/java/com/robj/deviceutils/PermissionsUtil.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | import android.content.Context; 4 | import android.content.pm.PackageManager; 5 | import android.os.Build; 6 | import android.support.v4.content.ContextCompat; 7 | 8 | /** 9 | * Created by Rob J on 25/09/16. 10 | */ 11 | class PermissionsUtil { 12 | 13 | public static boolean hasPermission(Context context, String permission) { 14 | if(Build.VERSION.SDK_INT >= 23) 15 | return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(context, permission); 16 | return true; 17 | } 18 | 19 | public static class PermissionException extends RuntimeException { 20 | public final String missingPermission; 21 | public PermissionException(String missingPermission) { 22 | this.missingPermission = missingPermission; 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /deviceutils/src/main/java/com/robj/deviceutils/WifiUtils.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.net.NetworkInfo; 6 | import android.net.wifi.WifiConfiguration; 7 | import android.net.wifi.WifiInfo; 8 | import android.net.wifi.WifiManager; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | import io.reactivex.Observable; 14 | 15 | /** 16 | * Created by Rob J on 16/06/17. 17 | */ 18 | 19 | public class WifiUtils { 20 | 21 | public static Observable> getSavedWifiNetworks(Context context) { 22 | return Observable.create(subscriber -> { 23 | WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); 24 | List wifiNetworks = wifiManager.getConfiguredNetworks(); 25 | List devices = new ArrayList(); 26 | if(wifiNetworks != null && wifiNetworks.size() > 0) 27 | for(WifiConfiguration wifiConfiguration : wifiNetworks) { 28 | Device device = new Device(wifiConfiguration); 29 | devices.add(device); 30 | } 31 | if(subscriber != null && !subscriber.isDisposed()) { 32 | subscriber.onNext(devices); 33 | subscriber.onComplete(); 34 | } 35 | }); 36 | } 37 | 38 | @SuppressLint("MissingPermission") 39 | public static String getWifiName(Context context, String typeIdentifier) { 40 | WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); 41 | List wifiConfigurations = wifiMgr.getConfiguredNetworks(); 42 | if(wifiConfigurations != null) { 43 | for (WifiConfiguration wifiConfiguration : wifiConfigurations) 44 | if (String.valueOf(wifiConfiguration.networkId).equals(typeIdentifier)) 45 | return wifiConfiguration.SSID; 46 | } 47 | return context.getString(R.string.device_name_unknown); 48 | } 49 | 50 | public static String getWifiId(WifiInfo wifiInfo) { 51 | return String.valueOf(wifiInfo.getNetworkId()); 52 | } 53 | 54 | private static String getWifiId(WifiConfiguration wifiConfiguration) { 55 | return String.valueOf(wifiConfiguration.networkId); 56 | } 57 | 58 | @SuppressLint("MissingPermission") 59 | public static WifiInfo getConnectedWifi(Context context) { 60 | WifiManager manager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); 61 | if (manager.isWifiEnabled()) { 62 | WifiInfo wifiInfo = manager.getConnectionInfo(); 63 | if (wifiInfo != null) { 64 | NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); 65 | if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { 66 | return wifiInfo; 67 | } 68 | } 69 | } 70 | return null; 71 | } 72 | 73 | public static Observable> getConnectedWifiObservable(Context context) { 74 | return Observable.create(subscriber -> { 75 | try { 76 | WifiInfo wifiInfo = getConnectedWifi(context); 77 | if(subscriber != null && !subscriber.isDisposed()) { 78 | if (wifiInfo != null) 79 | subscriber.onNext(new Optional(wifiInfo)); 80 | else 81 | subscriber.onNext(new Optional(null)); 82 | subscriber.onComplete(); 83 | } 84 | } catch (Exception e) { 85 | if(!subscriber.isDisposed()) 86 | subscriber.onError(e); 87 | } 88 | }); 89 | } 90 | 91 | public static class Device extends BaseDevice { 92 | 93 | protected Device(WifiConfiguration wifiConfiguration) { 94 | super(String.valueOf(wifiConfiguration.networkId), wifiConfiguration.SSID); 95 | } 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /deviceutils/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | DeviceUtils 3 | Unknown 4 | 5 | -------------------------------------------------------------------------------- /deviceutils/src/test/java/com/robj/deviceutils/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.robj.deviceutils; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iamrobj/DeviceUtils/72028964a3ea8006990e5078305050dbbfff3fd1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Nov 23 14:11:03 GMT 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':deviceutils' 2 | --------------------------------------------------------------------------------