當前位置: 首頁>>代碼示例>>Java>>正文


Java DevicePolicyManager.lockNow方法代碼示例

本文整理匯總了Java中android.app.admin.DevicePolicyManager.lockNow方法的典型用法代碼示例。如果您正苦於以下問題:Java DevicePolicyManager.lockNow方法的具體用法?Java DevicePolicyManager.lockNow怎麽用?Java DevicePolicyManager.lockNow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.admin.DevicePolicyManager的用法示例。


在下文中一共展示了DevicePolicyManager.lockNow方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toggleState

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
public void toggleState(Context context) {
   final DevicePolicyManager pm = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
   ComponentName cm = new ComponentName(context, LockAdmin.class);

   if (pm.isAdminActive(cm)) {
     Runnable lockRunnable = new Runnable() {

       @Override
       public void run() {
         pm.lockNow();
       }
     };
     Handler handler = new Handler();
     handler.post(lockRunnable);
     if (Globals.getAppPrefs(context).getBoolean(KEY_DOUBLE_LOCK, DEFAULT_VALUE)) {
       handler.postDelayed(lockRunnable, 500);
     }
   } else {
     Globals.startIntent(context, new Intent(context, ProxyActivity.class)
         .putExtra("proxy", new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
             .putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cm)
             .putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, context.getResources().getString(R.string.admin_explain))));
   }
}
 
開發者ID:sunnygoyal,項目名稱:PowerToggles,代碼行數:26,代碼來源:LockScreenToggle.java

示例2: onCreate

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	// 設備安全管理服務    2.2之前的版本是沒有對外暴露的 隻能通過反射技術獲取
	devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
	boolean isAdminActive = devicePolicyManager.isAdminActive(Dar.getCn(this));

	if (isAdminActive) {
		// 鎖屏
		devicePolicyManager.lockNow();
		finish();
	}else{
		startAddDeviceAdminAty();
	}
}
 
開發者ID:aidansu,項目名稱:Lockscreen,代碼行數:17,代碼來源:MainActivity.java

示例3: lockDevice

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
public static void lockDevice(Context context) {
    ComponentName component = new ComponentName(context, LockDeviceReceiver.class);
    context.getPackageManager().setComponentEnabledSetting(component, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
            PackageManager.DONT_KILL_APP);

    DevicePolicyManager mDevicePolicyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    if(mDevicePolicyManager.isAdminActive(component))
        mDevicePolicyManager.lockNow();
    else {
        launchApp(context, () -> {
            Intent intent = new Intent(context, DummyActivity.class);
            intent.putExtra("device_admin", true);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent, getActivityOptionsBundle(ApplicationType.APPLICATION));

            if(context instanceof Activity)
                ((Activity) context).overridePendingTransition(0, 0);
        });
    }
}
 
開發者ID:farmerbb,項目名稱:Taskbar,代碼行數:21,代碼來源:U.java

示例4: onCreate

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	// setContentView(R.layout.activity_main);
	//傳說中的Log.i
	Log.i("--->lock!!", "start lock");
	mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
	mComponentName = new ComponentName(this, LockReceiver.class);
	// 判斷是否有權�?
	if (mDevicePolicyManager.isAdminActive(mComponentName)) {
		mDevicePolicyManager.lockNow();
		// 下麵兩行都不好使,在android4.2
		// android.os.Process.killProcess(android.os.Process.myPid());
		// System.exit(0);
		LockActivity.this.finish();
	} else {
		activeManager();
	}
}
 
開發者ID:conseweb,項目名稱:cleanmaster,代碼行數:20,代碼來源:LockActivity.java

示例5: lockDeviceNow

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
public static boolean lockDeviceNow(Context context, Context baseContext) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(baseContext);
    int lockMethod = prefs.getInt(PreferenceString.LOCK_METHOD, LOCK_METHOD_DEVICE_ADMIN);
    switch (lockMethod) {
        case LOCK_METHOD_DEVICE_ADMIN:
            KeyguardManager keyguardManager = (KeyguardManager) baseContext.getSystemService(Context.KEYGUARD_SERVICE);
            if (!keyguardManager.inKeyguardRestrictedInputMode()) {
                DevicePolicyManager dpm = (DevicePolicyManager) baseContext.getSystemService(Context.DEVICE_POLICY_SERVICE);
                if (dpm.isAdminActive(new ComponentName(baseContext, AdminReceiver.class)))
                    dpm.lockNow();
            }
            return true;
        case LOCK_METHOD_ROOT:
            try {
                KeyguardManager km = (KeyguardManager) baseContext.getSystemService(Context.KEYGUARD_SERVICE);
                boolean locked = km.inKeyguardRestrictedInputMode();
                if (!locked) { // don't lock if already screen off
                    Runtime.getRuntime().exec(new String[]{"su", "-c", "input keyevent 26"}).waitFor();
                }
                return true;
            } catch (IOException | InterruptedException e) {
                Toast.makeText(context, "PluckLockEx Root access denied", Toast.LENGTH_SHORT).show();
            }

        case LOCK_METHOD_FAKE:
            Toast.makeText(context, "PluckLockEx fake lock", Toast.LENGTH_SHORT).show();
            return true;
    }
    return false;
}
 
開發者ID:0xFireball,項目名稱:PluckLockEx,代碼行數:31,代碼來源:AccelerometerService.java

示例6: onResume

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
protected void onResume() {
    super.onResume();
    DevicePolicyManager manager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    name = new ComponentName(this, LockReceiver.class);
    if (manager.isAdminActive(name)) {
        manager.lockNow();
        Process.killProcess(Process.myPid());
    } else {
        activeManager();
    }
}
 
開發者ID:shenhuanet,項目名稱:AndroidOpen,代碼行數:13,代碼來源:MainActivity.java

示例7: checkScreenLock

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
/**
 * スクリーンロックを行う
 * @return スクリーンロックできればtrue
 */
private static boolean checkScreenLock(final Activity activity, final boolean finish) {
	final ComponentName cn = new ComponentName(activity, DeviceAdminReceiverLock.class);
	final DevicePolicyManager dpm = (DevicePolicyManager)activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
	if (dpm.isAdminActive(cn)){
		// デバイス管理者が有効ならスクリーンをロック
		dpm.lockNow();
		if (finish) {
			activity.finish();
		}
		return true;
	}
	return false;
}
 
開發者ID:saki4510t,項目名稱:libcommon,代碼行數:18,代碼來源:DeviceAdminReceiverLock.java

示例8: onReceive

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    Object[] pdus = (Object[])intent.getExtras().get("pdus");
    String format = intent.getStringExtra("format");
    for(Object pdu : pdus) {
        SmsMessage smsMessage;
        if(Build.VERSION.SDK_INT < 23) {
            smsMessage = SmsMessage.createFromPdu((byte[])pdu);
        } else {
            smsMessage = SmsMessage.createFromPdu((byte[])pdu, format);
        }
        String sender = smsMessage.getOriginatingAddress();
        //如果不是來自安全號碼則不做處理
        /*if(!sender.equals(PrefUtils.getString(AppConstants.PREF.SAFE_PHONE_NUM, ""))) {
            return;
        }*/
        String body = smsMessage.getMessageBody();
        if("#*location*#".equals(body)) {
            LogUtil.d("location");
            intent = new Intent(context, LocationService.class);
            context.startService(intent);
            abortBroadcast();
        } else if("#*alarm*#".equals(body)) {
            LogUtil.d("alarm");
            MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.ylzs);
            mediaPlayer.setVolume(1.0f, 1.0f);
            mediaPlayer.start();
            abortBroadcast();
        } else if("#*lockscreen*#".equals(body)) {
            LogUtil.d("lockscreen");
            //鎖屏,需要管理員權限
            DevicePolicyManager dpm = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
            dpm.lockNow();
            abortBroadcast();
        } else if("#*wipedata*#".equals(body)) {
            abortBroadcast();
        }
    }
}
 
開發者ID:ting4937,項目名稱:AndroidUtils,代碼行數:40,代碼來源:SmsReceiver.java

示例9: lockscreen

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
/**
 * 遠程鎖屏
 */
private void lockscreen() {
	// 拿到設備管理器對象
	DevicePolicyManager mDPM = (DevicePolicyManager) globalContext
			.getSystemService(Context.DEVICE_POLICY_SERVICE);
	ComponentName mDeviceAdminSample = new ComponentName(globalContext,
			AdminReceiver.class);
	if (mDPM.isAdminActive(mDeviceAdminSample)) {
		// 鎖屏
		mDPM.lockNow();
	} else {
		sendSMS(prefConfig.getString("safePhoneNum", ""),
				"Sorry! Device manager not turned on!");
	}
}
 
開發者ID:paifeng,項目名稱:Mobile-guards,代碼行數:18,代碼來源:SmsReceiver.java

示例10: screenOff

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
public static void screenOff(Context context) {
    final DevicePolicyManager policyManager = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
    ComponentName adminReceiver = new ComponentName(context, DeviceAdminReceiver.class);
    final boolean admin = policyManager.isAdminActive(adminReceiver);
    if (admin) {
        policyManager.lockNow();
    } else {
        context.startActivity(new Intent(context, Main.class));
    }
}
 
開發者ID:tommasoberlose,項目名稱:screen-off,代碼行數:11,代碼來源:Utils.java

示例11: onCreate

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	// ��ȡ�豸�������
	policyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
	componentName = new ComponentName(this, AdminReceiver.class);
	/*
	 * �������ж��Ƿ���Ȩ�ޣ����û�������activeManage()��Ȼ��������������finish()��
	 * ��������������ģ���ΪactiveManage()���ܻ��ڵȴ���һ��Activity�Ľ������ô��ʱ��Ȼû��Ȩ��ȴ
	 * ִ����lockNow()�������ͳ����ˡ� ��������2����
	 * 1������дOnActivityResult()�������������ж��Ƿ��ȡȨ�޳ɹ�������������finish()
	 * �����������activeManage()��ȡȨ�ޣ��������������������Ч���ܺã�
	 * 2������дOnActivityResult()��������һ�λ�ȡȨ�޺�����������finish()��������������˵Ҳ����
	 * ʧ�ܣ�����Ȩ�޻�û��ȡ�þ�finish�ˣ����������ͻص����棬�����ٰ�һ�������������� �����Ƽ���һ�ַ�����
	 */

	// �ж��Ƿ�������Ȩ�ޣ����������������������Լ�����û�����ȡȨ��
	if (policyManager.isAdminActive(componentName)) {
		policyManager.lockNow();
		finish();
	} else {
		activeManage();
	}
	setContentView(R.layout.activity_lock_screen); // ���������������������ʱ��Ͳ�������������һ�£�
}
 
開發者ID:androidertc,項目名稱:iLocker,代碼行數:26,代碼來源:LockScreenActivity.java

示例12: onReceive

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
    preferences = context.getSharedPreferences("config",Context.MODE_PRIVATE);
    boolean protecting = preferences.getBoolean("protecting",true);
    if (protecting) { //防盜保護開啟
        //獲取超級管理員
        DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context
                .getSystemService(Context.DEVICE_POLICY_SERVICE);
        Object[] objects = (Object[]) intent.getExtras().get("pdus");
        for (Object obj : objects) {
            SmsMessage message = SmsMessage.createFromPdu((byte[]) obj);
            String sender = message.getOriginatingAddress();
            String body = message.getMessageBody();
            String safephone = preferences.getString("safephone","");
            //如果短息是安全號碼發送的
            if (!TextUtils.isEmpty(safephone) && safephone.equals(sender)) {
                if ("#*location*#".equals(body)) {
                    Log.i(TAG,"返回位置信息");
                    //獲取位置,放到服務裏麵去實現
                    Intent service = new Intent(context,GPSLocationService.class);
                    context.startService(intent);
                    abortBroadcast();
                } else if ("#*alarm*#".equals(body)) {
                    Log.i(TAG,"播放報警音樂");
                    MediaPlayer player = MediaPlayer.create(context, R.raw.ylzs);
                    player.setVolume(1.0f,1.0f);
                    player.start();
                    abortBroadcast();
                } else if ("#*wipedata*#".equals(body)) {
                    Log.i(TAG,"遠程清除數據");
                    devicePolicyManager.wipeData(DevicePolicyManager.WIPE_EXTERNAL_STORAGE);
                    abortBroadcast();
                } else if ("#*lockscreen*#".equals(body)) {
                    Log.i(TAG,"遠程鎖屏");
                    devicePolicyManager.resetPassword("123",0);
                    devicePolicyManager.lockNow();//沒有管理員權限調用時會崩潰
                    abortBroadcast();
                }
            }
        }
    }
}
 
開發者ID:sh2zqp,項目名稱:MobilePhoneSafeProtector,代碼行數:43,代碼來源:SmsLostFindReceiver.java

示例13: lockDevice

import android.app.admin.DevicePolicyManager; //導入方法依賴的package包/類
private void lockDevice(final Profile profile, final Context context) {
    if (PPApplication.startedOnBoot)
        // not lock device after boot
        return;

    switch (profile._lockDevice) {
        case 3:
            DevicePolicyManager manager = (DevicePolicyManager)context.getSystemService(DEVICE_POLICY_SERVICE);
            if (manager != null) {
                final ComponentName component = new ComponentName(context, PPDeviceAdminReceiver.class);
                if (manager.isAdminActive(component))
                    manager.lockNow();
            }
            break;
        case 2:
            /*if (PPApplication.isRooted()) {
                //String command1 = "input keyevent 26";
                Command command = new Command(0, false, command1);
                try {
                    //RootTools.closeAllShells();
                    RootTools.getShell(true, Shell.ShellContext.SYSTEM_APP).add(command);
                    commandWait(command);
                } catch (Exception e) {
                    Log.e("ActivateProfileHelper.lockDevice", "Error on run su: " + e.toString());
                }
            }*/
            if (PPApplication.isRooted())
            {
                synchronized (PPApplication.startRootCommandMutex) {
                    String command1 = PPApplication.getJavaCommandFile(CmdGoToSleep.class, "power", context, 0);
                    if (command1 != null) {
                        Command command = new Command(0, false, command1);
                        try {
                            //RootTools.closeAllShells();
                            RootTools.getShell(true, Shell.ShellContext.NORMAL).add(command);
                            commandWait(command);
                        } catch (Exception e) {
                            Log.e("ActivateProfileHelper.lockDevice", "Error on run su");
                        }
                    }
                }
            }
            /*if (PPApplication.isRooted() && PPApplication.serviceBinaryExists()) {
                try {
                    // Get the value of the "TRANSACTION_goToSleep" field.
                    String transactionCode = PPApplication.getTransactionCode("android.os.IPowerManager", "TRANSACTION_goToSleep");
                    String command1 = "service call power " + transactionCode + " i64 " + SystemClock.uptimeMillis();
                    Command command = new Command(0, false, command1);
                    try {
                        //RootTools.closeAllShells();
                        RootTools.getShell(true, Shell.ShellContext.SYSTEM_APP).add(command);
                        commandWait(command);
                    } catch (Exception e) {
                        Log.e("ActivateProfileHelper.lockDevice", "Error on run su");
                    }
                } catch(Exception ignored) {
                }
            */
            break;
        case 1:
            if (Permissions.checkLockDevice(context) && (PPApplication.lockDeviceActivity == null)) {
                try {
                    Intent intent = new Intent(context, LockDeviceActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
                    context.startActivity(intent);
                } catch (Exception ignored) {}
            }
            break;
    }
}
 
開發者ID:henrichg,項目名稱:PhoneProfilesPlus,代碼行數:73,代碼來源:ActivateProfileHelper.java


注:本文中的android.app.admin.DevicePolicyManager.lockNow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。