我做了一个android sms应用程序,我发送和接收短信作为Android消息应用程序这样做.现在我已将目标设置为4.4(Android KitKat版本),但Android KitKat具有新的"默认消息"应用程序设置,用户可以一次选择一个应用程序进行消息传递.我按照这个站点的步骤选择我的短信应用程序作为默认应用程序的选项,但在设置我的应用程序从未出现在选择默认消息应用程序的弹出窗口.
下面是我从guid中使用的java代码
if( androidOS.contains("4.4") ){
if (! Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName) ) {
// App is not default.
// Show the "not currently set as the default SMS app" interface
builder = new AlertDialog.Builder(MyConversation.this);
builder.setMessage("Shoot The Messenger is not set as your default messaging app. Do you want to set it default?")
.setCancelable(false)
.setTitle("Alert!")
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@TargetApi(19)
public void onClick(DialogInterface dialog, int …Run Code Online (Sandbox Code Playgroud) 我正在尝试替换默认的 android 电话应用程序。更具体地说,我想在每次执行呼叫操作时启动我的自定义电话呼叫屏幕。
我知道这是可能的,因为 Android 的 API 24(版本 7.0 - Nougat)但我没有找到关于如何实现这一点的参考。为了清楚起见,我不想显示 call screen 的覆盖布局。我想将我的通话应用设置为默认值。
我在这里发现了一个类似的 sms 应用程序问题:Stackoverflow - replace default sms app。答案清楚地表明您需要列出 sms 应用程序的所有组件,以便能够将其设置为 android 设置中的默认应用程序。但我找不到电话组件的任何参考。
我怎样才能做到这一点?
作为参考,这是我的清单文件:
<?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"/> …Run Code Online (Sandbox Code Playgroud) 因此,我已按照此指南显示收到短信时的简单吐司.虽然它在应用程序运行时正常工作,但当我进入设置并强制关闭应用程序时,它会停止工作.
我在StackOverflow上检查了很多关于simmilar问题的答案,但没有人真正回答是否(以及如何)在每次收到短信时都可以执行一段代码,而不会将应用程序设置为设备上的默认短信应用程序(Android) 4.4或以上版本).是吗?
考虑甚至可以停止服务,当发生这种情况时,服务不再是解决方案.
我对API等级19+感兴趣
谢谢
您好,我正在努力将我的应用程序兼容性更新为 android 10 和 11,之前我将我的应用程序设置为默认短信应用程序并从我的应用程序接收和发送新短信,更改默认短信应用程序的意图在 android 10 以下工作正常,但它不是显示更改 Android 10 上弹出的默认短信应用程序
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName)
startActivity(intent)
Run Code Online (Sandbox Code Playgroud)
如果有人知道 android 10 发生了什么变化,请提出建议,因为我无法在developer.android.com 上找到任何更改,提前致谢