diff --git a/app/build.gradle b/app/build.gradle index 63c93d8..c16e642 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -25,6 +25,5 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - compile project(path: ':permission') -// api 'com.blankj:utilcode:1.25.9' + implementation project(path: ':permission') } diff --git a/app/src/main/java/com/mingyuers/permissionanywhere/MainActivity.java b/app/src/main/java/com/mingyuers/permissionanywhere/MainActivity.java index 6e859c5..683261e 100644 --- a/app/src/main/java/com/mingyuers/permissionanywhere/MainActivity.java +++ b/app/src/main/java/com/mingyuers/permissionanywhere/MainActivity.java @@ -2,8 +2,8 @@ import android.Manifest; import android.os.Build; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; import com.mingyuers.permission.PermissionAnywhere; import com.mingyuers.permission.PermissionCallback; @@ -17,7 +17,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - PermissionAnywhere.requestPermission(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CALL_PHONE} + PermissionAnywhere.requestPermission(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CALL_PHONE} , new PermissionCallback() { @Override public void onComplete(List grantedPermissions, List deniedPermissions, List alwaysDeniedPermissions) { diff --git a/permission/build.gradle b/permission/build.gradle index f240bb3..cfdeced 100644 --- a/permission/build.gradle +++ b/permission/build.gradle @@ -34,4 +34,7 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + + implementation 'com.blankj:utilcode:1.25.9' + } diff --git a/permission/permission.iml b/permission/permission.iml index f8a4474..05a0203 100644 --- a/permission/permission.iml +++ b/permission/permission.iml @@ -132,5 +132,6 @@ + \ No newline at end of file diff --git a/permission/src/main/java/com/mingyuers/permission/PermissionAnywhere.java b/permission/src/main/java/com/mingyuers/permission/PermissionAnywhere.java index 23d617a..7766029 100644 --- a/permission/src/main/java/com/mingyuers/permission/PermissionAnywhere.java +++ b/permission/src/main/java/com/mingyuers/permission/PermissionAnywhere.java @@ -5,6 +5,8 @@ import android.os.Build; import android.support.annotation.RequiresApi; +import com.blankj.utilcode.util.ActivityUtils; + /*** * Created by fangm on 2019-11-18 14:29 @@ -28,4 +30,10 @@ public void onAttach() { FragmentTransaction fragmentTransaction = context.getFragmentManager().beginTransaction(); fragmentTransaction.add(permissionFragment, "permissionFragment@777").commit(); } + + @RequiresApi(api = Build.VERSION_CODES.M) + public static void requestPermission(final String[] permissions, PermissionCallback permissionCallback) { + Activity context = ActivityUtils.getTopActivity(); + requestPermission(context,permissions,permissionCallback); + } }