fix
This commit is contained in:
@@ -6,7 +6,7 @@ import android.content.Intent;
|
|||||||
|
|
||||||
import com.rnwalletman.IncomingCallNotificationHelper;
|
import com.rnwalletman.IncomingCallNotificationHelper;
|
||||||
|
|
||||||
/** 处理来电通知里的接听 / 挂断广播 */
|
/** 处理来电通知 Accept / Decline 广播(通知 action 广播,系统允许 startActivity)*/
|
||||||
public class CallActionReceiver extends BroadcastReceiver {
|
public class CallActionReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
public static final String ACTION_ACCEPT = "com.rnpay.CALL_ACCEPT";
|
public static final String ACTION_ACCEPT = "com.rnpay.CALL_ACCEPT";
|
||||||
@@ -15,12 +15,19 @@ public class CallActionReceiver extends BroadcastReceiver {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context ctx, Intent intent) {
|
public void onReceive(Context ctx, Intent intent) {
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
if (!ACTION_ACCEPT.equals(action) && !ACTION_DECLINE.equals(action)) return;
|
||||||
|
|
||||||
|
IncomingCallNotificationHelper.cancelRingThread();
|
||||||
IncomingCallNotificationHelper.cancel(ctx);
|
IncomingCallNotificationHelper.cancel(ctx);
|
||||||
|
|
||||||
if (ACTION_ACCEPT.equals(action)) {
|
String result = ACTION_ACCEPT.equals(action) ? "accept" : "decline";
|
||||||
IncomingCallNotificationHelper.deliverCallResult(ctx, "accept");
|
IncomingCallNotificationHelper.deliverCallResult(ctx, result);
|
||||||
} else if (ACTION_DECLINE.equals(action)) {
|
|
||||||
IncomingCallNotificationHelper.deliverCallResult(ctx, "decline");
|
Intent launch = ctx.getPackageManager().getLaunchIntentForPackage(ctx.getPackageName());
|
||||||
|
if (launch != null) {
|
||||||
|
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
ctx.startActivity(launch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ public class IncomingCallActivity extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
if (getIntent().getBooleanExtra("auto_accept", false)
|
||||||
|
|| getIntent().getBooleanExtra("auto_decline", false)) {
|
||||||
|
setTheme(android.R.style.Theme_Translucent_NoTitleBar);
|
||||||
|
}
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||||
@@ -68,18 +72,21 @@ public class IncomingCallActivity extends Activity {
|
|||||||
String caller = getIntent().getStringExtra("caller");
|
String caller = getIntent().getStringExtra("caller");
|
||||||
int ringDuration = getIntent().getIntExtra("ringDuration", 30);
|
int ringDuration = getIntent().getIntExtra("ringDuration", 30);
|
||||||
boolean autoAccept = getIntent().getBooleanExtra("auto_accept", false);
|
boolean autoAccept = getIntent().getBooleanExtra("auto_accept", false);
|
||||||
|
boolean autoDecline = getIntent().getBooleanExtra("auto_decline", false);
|
||||||
if (caller == null || caller.isEmpty()) caller = "Unknown";
|
if (caller == null || caller.isEmpty()) caller = "Unknown";
|
||||||
|
|
||||||
// 全屏模式由 setFullScreenIntent 触发,Activity 起来后立即取消通知,下拉栏不残留
|
// 立即打断 ring 线程(防止振动重启),再取消通知+停振动
|
||||||
|
IncomingCallNotificationHelper.cancelRingThread();
|
||||||
IncomingCallNotificationHelper.cancel(this);
|
IncomingCallNotificationHelper.cancel(this);
|
||||||
|
|
||||||
// 通知栏 Answer 按钮直接触发:跳过 UI,deliver accept 后进 app
|
// 通知栏 Accept / Decline 按钮:透明 Activity,deliver 结果后进 app,用户无感知
|
||||||
if (autoAccept) {
|
if (autoAccept || autoDecline) {
|
||||||
resultDelivered = true;
|
resultDelivered = true;
|
||||||
IncomingCallNotificationHelper.cancel(this);
|
IncomingCallNotificationHelper.deliverCallResult(this, autoAccept ? "accept" : "decline");
|
||||||
IncomingCallNotificationHelper.deliverCallResult(this, "accept");
|
|
||||||
launchMainApp(caller);
|
launchMainApp(caller);
|
||||||
|
overridePendingTransition(0, 0);
|
||||||
finish();
|
finish();
|
||||||
|
overridePendingTransition(0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,10 +224,13 @@ public class IncomingCallActivity extends Activity {
|
|||||||
private void launchMainApp(String caller) {
|
private void launchMainApp(String caller) {
|
||||||
Intent launch = getPackageManager().getLaunchIntentForPackage(getPackageName());
|
Intent launch = getPackageManager().getLaunchIntentForPackage(getPackageName());
|
||||||
if (launch != null) {
|
if (launch != null) {
|
||||||
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
launch.putExtra("from_call", true);
|
launch.putExtra("from_call", true);
|
||||||
launch.putExtra("caller", caller);
|
launch.putExtra("caller", caller);
|
||||||
startActivity(launch);
|
// 跨 Task 切换用 ActivityOptions 禁动画,overridePendingTransition 对此无效
|
||||||
|
android.app.ActivityOptions opts =
|
||||||
|
android.app.ActivityOptions.makeCustomAnimation(this, 0, 0);
|
||||||
|
startActivity(launch, opts.toBundle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,6 +308,36 @@ public class IncomingCallActivity extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onNewIntent(Intent intent) {
|
||||||
|
super.onNewIntent(intent);
|
||||||
|
setIntent(intent);
|
||||||
|
boolean autoAccept = intent.getBooleanExtra("auto_accept", false);
|
||||||
|
boolean autoDecline = intent.getBooleanExtra("auto_decline", false);
|
||||||
|
if ((autoAccept || autoDecline) && !resultDelivered) {
|
||||||
|
resultDelivered = true;
|
||||||
|
if (countDown != null) countDown.cancel();
|
||||||
|
stopRingtone();
|
||||||
|
stopVibrate();
|
||||||
|
IncomingCallNotificationHelper.cancelRingThread();
|
||||||
|
IncomingCallNotificationHelper.cancel(this);
|
||||||
|
String caller = intent.getStringExtra("caller");
|
||||||
|
if (caller == null || caller.isEmpty()) caller = "Unknown";
|
||||||
|
IncomingCallNotificationHelper.deliverCallResult(this, autoAccept ? "accept" : "decline");
|
||||||
|
launchMainApp(caller);
|
||||||
|
overridePendingTransition(0, 0);
|
||||||
|
finish();
|
||||||
|
overridePendingTransition(0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
stopRingtone();
|
||||||
|
stopVibrate();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
if (countDown != null) countDown.cancel();
|
if (countDown != null) countDown.cancel();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<item name="android:fitsSystemWindows">false</item>
|
<item name="android:fitsSystemWindows">false</item>
|
||||||
<item name="android:statusBarColor">#6a6b6f</item>
|
<item name="android:statusBarColor">#6a6b6f</item>
|
||||||
<item name="android:windowLightStatusBar">false</item>
|
<item name="android:windowLightStatusBar">false</item>
|
||||||
|
<item name="android:windowDisablePreview">true</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user