import android.Manifest; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.support.annotation.NonNull; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.widget.Button; import java.io.File; import butterknife.Bind; import butterknife.ButterKnife; /** * 创建新的文件夹 */ public class Main14Activity extends AppCompatActivity { @Bind(R.id.main14_btn) Button main14Btn; private final int REQUESTCODE = 101; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main14); ButterKnife.bind(this); main14Btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { test(); } }); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == REQUESTCODE) { if (permissions[0].equals(Manifest.permission.WRITE_EXTERNAL_STORAGE) && grantResults[0] == PackageManager.PERMISSION_GRANTED) { //用户同意 test(); } else { //用户不同意 } } } private void test() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { int checkSelfPermission = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE); if (checkSelfPermission == PackageManager.PERMISSION_DENIED) { requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUESTCODE); } } File appDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath() + "/mPic"); if (!appDir.exists()) { boolean isSuccess = appDir.mkdirs(); Log.d("isSuccess:" ,"----------0------------------"+isSuccess); } } }
android6.0创建新的文件夹
最新推荐文章于 2023-06-19 22:21:12 发布