Android 如何在查看应用程序信息的同时使用拨号程序?
情况: 我的应用程序的用户需要呼叫他们的联系人,并且仍然能够查看特殊的联系人信息 使用以下代码启动呼叫很容易:Android 如何在查看应用程序信息的同时使用拨号程序?,android,android-intent,android-dialer,Android,Android Intent,Android Dialer,情况: 我的应用程序的用户需要呼叫他们的联系人,并且仍然能够查看特殊的联系人信息 使用以下代码启动呼叫很容易: private void performDial(String numberString) { if ( checkSelfPermission(android.Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) { if (!numberString.equals("")) {
private void performDial(String numberString) {
if ( checkSelfPermission(android.Manifest.permission.CALL_PHONE) ==
PackageManager.PERMISSION_GRANTED) {
if (!numberString.equals("")) {
Uri number = Uri.parse("tel:" + numberString);
Intent dial = new Intent(Intent.ACTION_CALL, number);
startActivity(dial);
}
}
}
但是,拨号程序的GUI将隐藏联系人信息。要查看此联系人信息,用户必须执行两个步骤:
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
下面的片段可以让主应用程序重新回到前面
Intent intent = new Intent(this, MainActivity.class);
intent. addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
但是,拨号程序激活后,这两个片段将无法工作。如果在启动intent后直接执行这些片段,拨号程序将不会启动
以下是清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="copec.test2app">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ShowWebsite"> </activity>
<receiver android:name="copec.test2app.OutCallLogger" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</application>
非常感谢您的帮助。您不能隐藏拨号器。你可以做的是将你的应用程序移动到拨号器顶部的前台。使用
startActivity()
启动拨号程序后,应等待通话开始。您可以通过监视传出呼叫状态,或者只需等待几秒钟(您可以通过将以下代码包装到Runnable
中,然后使用postDelayed()
将其发布到Handler
来实现)。然后,要将应用程序移动到前台,请执行以下操作:
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("your.package.name");
getApplicationContext().startActivity(intent);
感谢您的响应,应用程序被移动到前台,这非常好。但是应用程序是新启动的,而不是移动到前台。这意味着以前的信息丢失。通过添加:intent.addFlags(intent.FLAG_ACTIVITY_NEW_TASK | intent.FLAG_ACTIVITY_SINGLE_TOP);工作正常。抱歉,这毫无意义。我想你可能看到了另一个错误。请执行以下操作进行检查:删除这两个标志,然后安装你的应用程序。然后在设置中使用强制停止来终止你的应用程序。然后点击主屏幕上的图标正常启动你的应用程序。然后检查它是否正常工作。请发布你的结果。执行您提到的步骤后,应用程序重新启动活动(在调试器中执行oncreate)。有了这两个标志,oncreate被跳过,应用程序弹出在前面。因此,这两个标志似乎可以使用,但没有。嗯。我很高兴你解决了这个问题,但这仍然没有意义。你能发布你的清单吗?只需编辑你的帖子并将其添加到原始问题中即可。