Skip to content

Commit

Permalink
#15
Browse files Browse the repository at this point in the history
  • Loading branch information
mylhyl committed Nov 5, 2021
1 parent fa31070 commit 6b13a92
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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'
}
14 changes: 9 additions & 5 deletions app/src/main/java/com/mylhyl/acp/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions library/src/main/java/com/mylhyl/acp/Acp.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public void request(AcpOptions options, AcpListener acpListener) {
mAcpManager.request(options, acpListener);
}

public void onDestroy() {
mAcpManager.onDestroy();
}

AcpManager getAcpManager() {
return mAcpManager;
}
Expand Down
16 changes: 7 additions & 9 deletions library/src/main/java/com/mylhyl/acp/AcpManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ synchronized void onRequestPermissionsResult(int requestCode, String[] permissio
if (mListener != null) {
mListener.onGranted();
}
onDestroy();
} else if (!deniedPermissions.isEmpty()) showDeniedDialog(deniedPermissions);
break;
}
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -213,9 +211,9 @@ private synchronized void showDeniedDialog(final List<String> 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() {
Expand All @@ -232,7 +230,7 @@ public void onClick(DialogInterface dialog, int which) {
/**
* 摧毁本库的 AcpActivity
*/
private void onDestroy() {
void onDestroy() {
if (internalActivity != null) {
internalActivity.finish();
internalActivity = null;
Expand Down
18 changes: 12 additions & 6 deletions library/src/main/java/com/mylhyl/acp/os/MeiZu.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}
}

0 comments on commit 6b13a92

Please sign in to comment.