我正在开发一个安全应用程序,如果用户拨打一个不经常拨打的电话号码并且他以前从未拨打过电话,则用户将不得不重新验证自己。为此,我想在检查电话号码后锁定电话。
public class outgoingCalls extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Log.v("onReceive", "In onReceive()");
if (confidence == 0) {
Log.v("onReceive","confidence zeroed");
Intent i = new Intent();
i.setClassName("abc.xyz.SECURITY","abc.xyz.SECURITY.lockActivity");
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
在这个新的Activity lockActivity中,我需要锁定我评论过的手机//LOCK PHONE
public class lockActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("lock","lockActivity onCreate method called");
// setContentView(R.layout.main);
Log.v("lock","locking");
// LOCK PHONE
}
}
手机没有被我尝试过的方法锁定。其中包括:
1. KeyguardManager mgr = (KeyguardManager) getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = mgr.newKeyguardLock("edu.Boston.SECURITY.lockActivity");
((KeyguardLock) lock).reenableKeyguard();
2. PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
manager.goToSleep(100);//int amountOfTime
3. PowerManager.WakeLock wl = manager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Tag");
wl.acquire();
wl.release();
4. WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);
Android清单文件具有以下权限
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
为什么我无法锁定手机?任何指针?非常感谢您的帮助。欣赏它!