diff --git a/app/build.gradle b/app/build.gradle index aa44955..b1ab9e9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 23 + compileSdkVersion 28 defaultConfig { applicationId "com.mylhyl.acp.sample" minSdkVersion 15 - targetSdkVersion 23 + targetSdkVersion 28 versionCode 1 versionName "20180425" } @@ -23,9 +23,9 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':library') - implementation 'com.android.support:appcompat-v7:23.1.1' - implementation 'com.android.support:support-v4:23.1.1' + implementation 'com.android.support:appcompat-v7:28.0.0' debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4' releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' androidTestImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' + implementation 'com.yanzhenjie.permission:support:2.0.1' } diff --git a/app/src/main/java/com/mylhyl/acp/sample/MainActivity.java b/app/src/main/java/com/mylhyl/acp/sample/MainActivity.java index 5cebf93..ed1da67 100644 --- a/app/src/main/java/com/mylhyl/acp/sample/MainActivity.java +++ b/app/src/main/java/com/mylhyl/acp/sample/MainActivity.java @@ -161,11 +161,15 @@ public void onGranted() { startActivity(intentCall); */ - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_CALL); - intent.setData(Uri.parse("tel:13800138000")); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(intent); + try { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_CALL); + intent.setData(Uri.parse("tel:13800138000")); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } catch (Exception e) { + e.printStackTrace(); + } } @Override diff --git a/library/src/main/java/com/mylhyl/acp/Acp.java b/library/src/main/java/com/mylhyl/acp/Acp.java index 406ea4e..b4b9849 100644 --- a/library/src/main/java/com/mylhyl/acp/Acp.java +++ b/library/src/main/java/com/mylhyl/acp/Acp.java @@ -27,6 +27,10 @@ public void request(AcpOptions options, AcpListener acpListener) { mAcpManager.request(options, acpListener); } + public void onDestroy() { + mAcpManager.onDestroy(); + } + AcpManager getAcpManager() { return mAcpManager; } diff --git a/library/src/main/java/com/mylhyl/acp/AcpManager.java b/library/src/main/java/com/mylhyl/acp/AcpManager.java index 339f787..27d3bef 100644 --- a/library/src/main/java/com/mylhyl/acp/AcpManager.java +++ b/library/src/main/java/com/mylhyl/acp/AcpManager.java @@ -89,7 +89,6 @@ synchronized void onRequestPermissionsResult(int requestCode, String[] permissio if (mListener != null) { mListener.onGranted(); } - onDestroy(); } else if (!deniedPermissions.isEmpty()) showDeniedDialog(deniedPermissions); break; } @@ -104,7 +103,6 @@ synchronized void onRequestPermissionsResult(int requestCode, String[] permissio */ synchronized void onActivityResult(int requestCode, int resultCode, Intent data) { if (mListener == null || mOptions == null || requestCode != REQUEST_CODE_SETTING) { - onDestroy(); return; } checkSelfPermission(); @@ -135,9 +133,9 @@ private synchronized void checkSelfPermission() { mDeniedPermissions.clear(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { Log.i(TAG, "Build.VERSION.SDK_INT < Build.VERSION_CODES.M"); - if (mListener != null) + if (mListener != null) { mListener.onGranted(); - onDestroy(); + } return; } String[] permissions = mOptions.getPermissions(); @@ -157,9 +155,9 @@ private synchronized void checkSelfPermission() { //检查如果没有一个拒绝响应 onGranted 回调 if (mDeniedPermissions.isEmpty()) { Log.i(TAG, "mDeniedPermissions.isEmpty()"); - if (mListener != null) + if (mListener != null) { mListener.onGranted(); - onDestroy(); + } return; } startAcpActivity(); @@ -213,9 +211,9 @@ private synchronized void showDeniedDialog(final List permissions) { .setNegativeButton(mOptions.getDeniedCloseBtn(), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - if (mListener != null) + if (mListener != null) { mListener.onDenied(permissions); - onDestroy(); + } } }) .setPositiveButton(mOptions.getDeniedSettingBtn(), new DialogInterface.OnClickListener() { @@ -232,7 +230,7 @@ public void onClick(DialogInterface dialog, int which) { /** * 摧毁本库的 AcpActivity */ - private void onDestroy() { + void onDestroy() { if (internalActivity != null) { internalActivity.finish(); internalActivity = null; diff --git a/library/src/main/java/com/mylhyl/acp/os/MeiZu.java b/library/src/main/java/com/mylhyl/acp/os/MeiZu.java index 1d1e469..d136231 100644 --- a/library/src/main/java/com/mylhyl/acp/os/MeiZu.java +++ b/library/src/main/java/com/mylhyl/acp/os/MeiZu.java @@ -1,9 +1,8 @@ package com.mylhyl.acp.os; -import android.content.ActivityNotFoundException; -import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; /** * Created by hupei on 2019/5/21 20:54. @@ -29,11 +28,18 @@ private static String getCls() { } @Override - public Intent createIntent() throws ActivityNotFoundException { + public Intent createIntent() throws PackageManager.NameNotFoundException { + Intent intent = new Intent(); - intent.setComponent(new ComponentName(PKG, getCls())); + intent.putExtra("packageName", context.getPackageName()); + intent.putExtra(EXTRA_PKG_NAME, context.getPackageName()); intent.putExtra(EXTRA_PKG, context.getPackageName()); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - return intent; + + intent.setClassName(PKG, getCls()); + if (OsHelper.isIntentAvailable(context, intent) && OsHelper.isActivityExported(context, intent)) { + return intent; + } + + return null; } }