Android Lock Application
Im trying to make an app that Locks all applications with a password because 'Kiosk Mode' cant be done as you can see in my question here ( disabling and hiding android navigation
Solution 1:
First of all , if your service isn't even starting , then check in AndroidManifest.xml
for this
<serviceandroid:name=".MyService"android:enabled="true" />
If it's starting then from what i understand , you are checking which apps are running when your service is started.
For now , just to test your code , implement an CountDownTimer , Which will check TOP Activity every 5 Second like
Protected CountDownTimercheck=newCountDownTimer(5000, 5000)
{
@OverridepublicvoidonTick(long millisUntilFinished)
{
//Do nothing here
}
@OverridepublicvoidonFinish()
{
PackageManagerpackageManager= getPackageManager();
IntentmainIntent=newIntent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> appList = packageManager.queryIntentActivities(mainIntent, 0);
Collections.sort(appList, newResolveInfo.DisplayNameComparator(packageManager));
List<PackageInfo> packs = packageManager.getInstalledPackages(0);
for(int i=0; i < packs.size(); i++)
{
PackageInfop= packs.get(i);
ApplicationInfoa= p.applicationInfo;
// skip system apps if they shall not be included//apps.add(p.packageName);
}
ActivityManagermActivityManager= (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager.getRunningTasks(1);
ActivityManager.RunningTaskInfoar= RunningTask.get(0);
StringactivityOnTop= ar.topActivity.getClassName();
if(!activityOnTop.equals("com.example.lock"))
{
IntentlockIntent=newIntent(this, LockScreen.class);
lockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(lockIntent);
}
this.cancel();
this.start();
}
};
Don't forget to start the countdowntimer from onCreate of service
check.start();
Post a Comment for "Android Lock Application"