經過大量的研究,我通過使用反射得到了正確的解決方案,我們可以實現它。有一個LockPatternUtils類,通過它我們可以獲取設備信息,下面是代碼。
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS}, 1);
//String a = Settings.Secure.getString(getContentResolver(),"lock_screen_owner_info");
//printLog("a : "+a);
Class<?> cl = null;
try {
cl = Class.forName("com.android.internal.widget.LockPatternUtils");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
Constructor<?> cons = cl.getConstructor(Context.class);
Object obj = cons.newInstance(this);
Class[] paramInt = new Class[1];
paramInt[0] = Integer.TYPE;
Method method = cl.getDeclaredMethod("getOwnerInfo", paramInt);
Log.d("b : " ,""+ method.invoke(obj, 0));
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
它不工作! – shadygoneinsane