zoukankan      html  css  js  c++  java
  • Android 判定手机是否root

    Android获取手机root的状态

    package com.app.demo;
    
    import java.io.File;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    
    public class AndroiddemoActivity extends Activity {
    	/** Called when the activity is first created. */
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.main);  
    	}
    	public void onclick(View v) {
    		Button button = (Button)v;
    		if (isRootSystem()) {
    			button.setText("root");
    		} else {
    			button.setText("not");
    		}  
    	} 
    
    	private final static int kSystemRootStateUnknow=-1;
    	private final static int kSystemRootStateDisable=0;
    	private final static int kSystemRootStateEnable=1;
    	private static int systemRootState=kSystemRootStateUnknow;
    
    	public static boolean isRootSystem()
    	{
    		if(systemRootState==kSystemRootStateEnable)
    		{
    			return true;
    		}
    		else if(systemRootState==kSystemRootStateDisable)
    		{
    
    			return false;
    		}
    		File f=null;
    		final String kSuSearchPaths[]={"/system/bin/","/system/xbin/","/system/sbin/","/sbin/","/vendor/bin/"};
    		try{
    			for(int i=0;i<kSuSearchPaths.length;i++)
    			{
    				f=new File(kSuSearchPaths[i]+"su");
    				if(f!=null&&f.exists())
    				{
    					systemRootState=kSystemRootStateEnable;
    					return true;
    				}
    			}
    		}catch(Exception e)
    		{
    		}
    		systemRootState=kSystemRootStateDisable;
    		return false;
    	}
    }


  • 相关阅读:
    78. Subsets
    [LintCode] 447 Search in a Big Sorted Array
    [LintCode] 585 Maximum Number in Mountain Sequence
    [LintCode] Search a 2D Matrix
    [LintCode] 459 Closest Number in Sorted Array
    [z]Google SPDY介绍
    Python Snippet
    python学习[二]
    [转]总结的几大驭下法宝
    python学习[一]
  • 原文地址:https://www.cnblogs.com/aikongmeng/p/3697374.html
Copyright © 2011-2022 走看看