code: package com.fdu.uiautomatortest;
  
  import android.Manifest;
  import android.content.Context;
  import android.content.pm.PackageManager;
  import android.support.v4.app.ActivityCompat;
  import android.support.v4.content.ContextCompat;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.util.Log;
  
  //import com.chaquo.python.PyObject;
  //import com.chaquo.python.Python;
  //import com.chaquo.python.android.AndroidPlatform;
  
  import java.util.ArrayList;
  
  public class MainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          initPermission();
  //        initPython();
      }
  
      private void initPermission() {
          String permissions[] = {
                  Manifest.permission.ACCESS_NETWORK_STATE,
                  Manifest.permission.INTERNET,
                  Manifest.permission.READ_EXTERNAL_STORAGE,
                  Manifest.permission.WRITE_EXTERNAL_STORAGE
          };
  
          ArrayList<String> toApplyList = new ArrayList<String>();
  
          for (String perm : permissions) {
              if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this, perm)) {
                  toApplyList.add(perm);
                  // 进入到这里代表没有权限.
  
              }
          }
          String tmpList[] = new String[toApplyList.size()];
          if (!toApplyList.isEmpty()) {
              ActivityCompat.requestPermissions(this, toApplyList.toArray(tmpList), 123);
          }
  
      }
  
  //    public void initPython(){
  //        if (! Python.isStarted()) {
  //            Python.start(new AndroidPlatform(this));
  //        }
  //    }
  
  }
  