问题描述
我正在尝试替换默认的Android电话应用.更具体地说,我想在每次执行通话操作时启动我的自定义电话屏幕.
I'm trying to replace the default android phone call app. More specifically I want to launch my custom phone call screen everytime a call action is performed.
我知道自Android的API 24(版本7.0-牛轧糖)以来,这是可能的,但是我没有找到有关如何实现此目的的参考.请注意,我不想显示呼叫屏幕的重叠式布局.我想将我的呼叫应用程序设置为默认应用程序.
I understand this is possible since Android's API 24 (Version 7.0 - Nougat) but I found no references on how to achieve this. Just to be clear, I do not want to show an overlay layout for the call screen. I want to set my call app as default.
我在这里找到了有关短信应用程序的类似问题: Stackoverflow-替换默认的短信应用程序.答案很明确,您需要列出sms应用程序的所有组件,以便能够将其设置为android设置中的默认应用程序.但是我找不到有关电话呼叫组件的任何参考.
I found a similar question for the sms app here: Stackoverflow - replace default sms app. The answer made it clear that you need to list all the components for the sms app in order to be able to set it as the default application in android's settings. But I can't find any reference for the phone call components.
我该如何实现?
作为参考,这是我的清单文件:
For reference this is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mynumbers">
<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"/>
<uses-permission android:name="android.permission.ANSWER_PHONE_CALLS"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="">
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.DIAL" />
<action android:name="android.intent.action.CALL_BUTTON" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme="tel"/>
</intent-filter>
</activity>
<activity
android:name=".NumberManagementActivity"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".CallActivity"
android:parentActivityName=".MainDialerActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainDialerActivity" />
<intent-filter>
<action android:name="android.permission.CALL_PHONE" />
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</activity>
<activity
android:name=".MainDialerActivity"
android:parentActivityName=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.DIAL" />
<action android:name="android.intent.action.CALL_BUTTON"/>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<action android:name="android.permission.CALL_PHONE"/>
<data android:scheme="tel"/>
</intent-filter>
</activity>
<receiver
android:name=".PhoneCallListener">
<intent-filter android:priority="1">
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<!-- Incoming call activity -->
<activity
android:name=".IncomingCallActivity"
android:configChanges="orientation"
android:label="@string/title_activity_fullscreen"
android:theme="@style/IncomingCallTheme">
<intent-filter>
<action android:name="android.intent.action.ANSWER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".DefaultConfigurationActivity"
android:parentActivityName=".MainActivity">
</activity>
</application>
</manifest>
推荐答案
我在整个Google上进行了搜索,最后找到了解决方案.现在我可以用自定义创建的应用替换默认的电话(呼叫)应用如果您在清单文件中添加了这些权限,则可以在->手机菜单->设置->应用程序->默认应用程序(右上角的菜单项)->默认呼叫应用程序中最终将您的应用程序更改为默认呼叫应用程序选择您的应用.
I have searched all over the google, and finally find a solution. now I can replace the default phone(calling) app with my custom created appIf you add those permissions in your manifest file you will able to change your app as default calling app in -> Phone Menu -> Settings -> Apps -> Default Apps (Menu item in right top corner) -> Default Calling apps and finally select your app.
这是权限列表
<uses-permission
android:name="android.permission.CALL_PRIVILEGED"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission
android:name="android.permission.MODIFY_PHONE_STATE"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="com.android.voicemail.permission.ADD_VOICEMAIL" />
<uses-permission android:name="com.android.voicemail.permission.READ_WRITE_ALL_VOICEMAIL" />
<uses-permission
android:name="android.permission.ALLOW_ANY_CODEC_FOR_PLAYBACK"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<!-- allow broadcasting secret code intents that reboot the phone -->
<uses-permission
android:name="android.permission.REBOOT"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!--
This tells the activity manager to not delay any of our activity
start requests, even if they happen immediately after the user
presses home.
-->
<uses-permission
android:name="android.permission.STOP_APP_SWITCHES"
tools:ignore="ProtectedPermissions" />
这篇关于更换默认手机APP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!