我正在开发应用程序锁应用程序。如果安装了这个 奇巧版设备中的应用 应用锁定及其 完美工作。棉花糖|(6.0( 版本设备初始 应用程序正在工作,如果我们重新启动设备应用程序锁定不是 工作,锁定的应用程序打开而不询问任何密码。 如果我们只是进入应用程序(应用程序锁定应用程序(并从应用程序退出其 完美工作。那一次它要求密码。
public class StartupServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
if (AppLockerPreference.getInstance(context).isAutoStart()){
if (AppLockerPreference.getInstance(context).isServiceEnabled()){
context.startService(new Intent(context, DetectorService.class));
}else{
AppLockerPreference.getInstance(context).saveServiceEnabled(false);
}
}
return;
}else if (AppLockerPreference.getInstance(context).isServiceEnabled()){
context.startService(new Intent(context, DetectorService.class));
}
}
}
public class AppLockerPreference implements OnSharedPreferenceChangeListener {
Context mContext;
public boolean isAutoStart() {
Log.d("AMK","AppLockerPreference1--->"+mApplicationList.length);
return mAutoStart;
}
public boolean isServiceEnabled() {
Log.d("AMK","AppLockerPreference2--->"+mApplicationList.length);
return mServiceEnabled;
}
public void saveServiceEnabled(boolean serviceEnabled) {
mServiceEnabled = serviceEnabled;
mPref.edit().putBoolean(PREF_SERVICE_ENABLED, mServiceEnabled);
}
public String[] getApplicationList() {
Log.d("AMK","AppLockerPreference3--->"+mApplicationList.length);
return mApplicationList;
}
public void saveApplicationList(String[] applicationList) {
mApplicationList = applicationList;
String combined = "";
for (int i=0; i<mApplicationList.length; i++){
combined = combined + mApplicationList[i] + ";";
}
mPref.edit().putString(PREF_APPLICATION_LIST, combined).commit();
}
private static final String PREF_SERVICE_ENABLED = "service_enabled";
private static final String PREF_APPLICATION_LIST = "application_list";
private static final String PREF_AUTO_START = "start_service_after_boot";
private static final String PREF_PASSWORD = "password";
/**
* Section for singleton pattern
*/
private SharedPreferences mPref;
private AppLockerPreference(Context context) {
mPref = PreferenceManager.getDefaultSharedPreferences(context);
mPref.registerOnSharedPreferenceChangeListener(this);
reloadPreferences();
}
private void reloadPreferences() {
mServiceEnabled = mPref.getBoolean(PREF_SERVICE_ENABLED, true);
mApplicationList = mPref.getString(PREF_APPLICATION_LIST, "").split(";");
Log.d("AMK","selectd apps--->"+mApplicationList);
mAutoStart = mPref.getBoolean(PREF_AUTO_START, true);
mPassword = mPref.getString(PREF_PASSWORD, "2468");
if (mPref.getBoolean("relock_policy", true)){
try{
mRelockTimeout = Integer.parseInt(mPref.getString("relock_timeout", "-1"));
}catch(Exception e){
mRelockTimeout = -1;
}
}else{
mRelockTimeout = -1;
}
}
private static AppLockerPreference mInstance;
public static AppLockerPreference getInstance(Context context){
return mInstance == null ?
(mInstance = new AppLockerPreference(context)) :
mInstance;
}
private boolean mServiceEnabled, mAutoStart;
private String[] mApplicationList;
private String mPassword;
private int mRelockTimeout;
public int getRelockTimeout(){
return mRelockTimeout;
}
public String getPassword() {
return mPassword;
}
public void savePassword(String password) {
mPassword = password;
mPref.edit().putString(PREF_PASSWORD, password);
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
reloadPreferences();
}
}
你能帮帮我吗?
检查设备是否是棉花糖并授予权限
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.MARSHMALLOW) {
// only for marshmallow and newer versions
}