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;
    	}
    }


  • 相关阅读:
    php 数组处理
    PHP 递归几种方法
    PHP取一算法
    oracle的db link
    sql2008破解加密存储过程
    ATT 解锁手机
    jQuery 通配符
    win10 Enable developer Mode
    Win8.1 远程桌面 凭据无法工作
    html5media.js 让浏览器兼容<Video><Audio> 标签
  • 原文地址:https://www.cnblogs.com/aikongmeng/p/3697374.html
Copyright © 2011-2022 走看看