我是android的新手。我正在开发一个用于锁定其他应用的应用。这是我的服务类。我可以从Android设备生成应用程序列表,从那里我可以选择每个应用程序进行锁定。在那之后运行MYService类。但我的应用程序并未锁定所选的应用程序,如What'sapp,Facebook等。它始终锁定当前(开发)应用程序。任何人都可以帮助我做什么来锁定像Facebook这样的选定的应用程序?此外,我们必须在什么时候调用服务类
public class MyService extends android.app.Service {
final class TheThread implements Runnable{
int serviceID ;
TheThread(int serviceID){
this.serviceID = serviceID;
}
@Override
public void run() {
synchronized(this){
try{
wait(10000);
}catch(InterruptedException e){
}
}
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(MyService.this, "Service started!!", Toast.LENGTH_LONG).show();
instance = this;
Thread thread = new Thread(new TheThread(startId));
thread.start();
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
}
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager.getRunningTasks(1);
ActivityManager.RunningTaskInfo ar = RunningTask.get(0);
String activityOnTop = ar.topActivity.getClassName();
Toast.makeText(MyService.this, "Activity .... : "+activityOnTop, Toast.LENGTH_LONG).show();
if(!activityOnTop.equals("com.package.name"))
{
Intent intent1 = getPackageManager().getLaunchIntentForPackage("com.package.name");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent1);
Toast.makeText(this, "My Service Running", Toast.LENGTH_LONG).show();
Intent lockIntent = new Intent(MyService.this, Lockscreen.class);
lockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
instance.startActivity(lockIntent);
}
////////////////////////////////////////////////////////////////////////////////
return START_STICKY;
}
答案 0 :(得分:1)
您应该查看Android安全模型。基本上,您无法通过vanilla安装访问其他应用程序。你是完全沙盒的。
https://developer.android.com/training/articles/security-tips.html