[英]How to set my sms app default in Android Kitkat?
I made an android sms app in which I am sending and receiving sms as android messaging app does so.我制作了一个 android 短信应用程序,我在其中发送和接收短信,就像 android 消息应用程序那样。 Now I have set my target to 4.4 (Android KitKat version) but Android KitKat has new "Default Messaging" app settings that user can select one app at a time for messaging.现在我已将目标设置为 4.4(Android KitKat 版本),但 Android KitKat 具有新的“默认消息”应用设置,用户可以一次选择一个应用进行消息传递。 I followed the steps from this site to select option for my sms app as default app but in the settings my app never showed up in the popup of selecting default messaging app.我按照此站点的步骤为我的短信应用程序选择选项作为默认应用程序,但在设置中,我的应用程序从未出现在选择默认消息传递应用程序的弹出窗口中。
Below is my java code I have used from the guid下面是我从 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 id) {
Intent intent =
new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
getPackageName());
startActivity(intent);
}
});
builder.show();
}
}
Also I added below code in Manifest
file.我还在Manifest
文件中添加了以下代码。
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-feature android:name="android.hardware.telephony.gsm"
android:required="false"/>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.WRITE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.NoTitle" >
<activity
android:name="coms3.shootmessenger.Mysplash"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
</activity>
<receiver android:name="coms3.shootmessenger.SmsReceiver"
android:permission="android.permission.BROADCAST_SMS" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
<!--
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
-->
</receiver>
<receiver android:name="com.example.bootreceiver.MyBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<receiver android:name="coms3.shootmessenger.MMSReceiver"
android:permission="android.permission.BROADCAST_WAP_PUSH">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>
<receiver android:process=":remote" android:name="AlarmManagerBroadcastReceiver"></receiver>
<receiver android:process=":remote" android:name="AlarmForPartyMessage"></receiver>
<receiver android:process=":remote" android:name="AlarmManagerMail"></receiver>
<activity
android:name="coms3.shootmessenger.ActivityFirstList"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityBase"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.SearchTab"
android:configChanges="keyboardHidden|orientation"
>
</activity>
<activity
android:name="coms3.shootmessenger.ActivityMail"
android:windowSoftInputMode="adjustPan"
>
</activity>
<activity
android:name="coms3.shootmessenger.ActivityScheduldMail"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait"
>
</activity>
<activity
android:name="coms3.shootmessenger.MessageTab" >
</activity>
<activity
android:name="coms3.shootmessenger.SettingsTab"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.MyConversation"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityDelayedSending"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityScheduldMessage"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityStealthMode"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivitySms"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityBlackList"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityDeleteMessage"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityDeleteone"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity android:name="coms3.shootmessenger.ActivitySmsnew" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
</intent-filter>
</activity>
<activity
android:name="coms3.shootmessenger.ActivityEventlist"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityScheduleList"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityCancelSchedule"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityCancelEvent"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityCancelMail"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.Activitytutorial"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.ActivityConversationtutorial"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity
android:name="coms3.shootmessenger.Aboutus"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" >
</activity>
<service android:name="coms3.shootmessenger.HeadlessSmsSendService"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</service>
</application>
UPDATE:更新:
Note: I am testing on Emulator... After following all steps I only see the default messaging app of Android not mine like in the image given below.注意:我正在 Emulator 上进行测试...在完成所有步骤后,我只能看到 Android 的默认消息传递应用程序,而不是我的,如下图所示。 Any type of help will be appreciated.任何类型的帮助将不胜感激。 Thanks in Advance.提前致谢。
The instructions you posted were correct - the issue is that you must implement all of the required capabilities:您发布的说明是正确的 - 问题是您必须实现所有必需的功能:
In a broadcast receiver, include an intent filter for SMS_DELIVER_ACTION
(" android.provider.Telephony.SMS_DELIVER
").在广播接收器中,包括SMS_DELIVER_ACTION
的意图过滤器(“ android.provider.Telephony.SMS_DELIVER
”)。 The broadcast receiver must also require the BROADCAST_SMS permission.广播接收器还必须需要 BROADCAST_SMS 权限。 This allows your app to directly receive incoming SMS messages.这允许您的应用程序直接接收传入的 SMS 消息。
In a broadcast receiver, include an intent filter for WAP_PUSH_DELIVER_ACTION
(" android.provider.Telephony.WAP_PUSH_DELIVER
") with the MIME type " application/vnd.wap.mms-message
".在广播接收器中,为WAP_PUSH_DELIVER_ACTION
(“ android.provider.Telephony.WAP_PUSH_DELIVER
”)包含一个具有 MIME 类型“ application/vnd.wap.mms-message
”的意图过滤器。 The broadcast receiver must also require the BROADCAST_WAP_PUSH permission.广播接收器还必须需要 BROADCAST_WAP_PUSH 权限。 This allows your app to directly receive incoming MMS messages.这允许您的应用程序直接接收传入的彩信。
In your activity that delivers new messages, include an intent filter for ACTION_SENDTO
(" android.intent.action.SENDTO
") with schemas, sms:
, smsto:
, mms:
, and mmsto:
.在您传递新消息的 Activity 中,包含ACTION_SENDTO
(“ android.intent.action.SENDTO
”)的意图过滤器,其中包含架构、 sms:
、 smsto:
、 mms:
和mmsto:
。 This allows your app to receive intents from other apps that want to deliver a message.这允许您的应用程序接收来自想要传递消息的其他应用程序的意图。
In a service, include an intent filter for ACTION_RESPONSE_VIA_MESSAGE
(" android.intent.action.RESPOND_VIA_MESSAGE
") with schemas, sms:
, smsto:
, mms:
, and mmsto:
.在服务中,为ACTION_RESPONSE_VIA_MESSAGE
(“ android.intent.action.RESPOND_VIA_MESSAGE
”)包含一个意图过滤器,包括模式、 sms:
、 smsto:
、 mms:
和mmsto:
。 This service must also require the SEND_RESPOND_VIA_MESSAGE
permission.此服务还必须需要SEND_RESPOND_VIA_MESSAGE
权限。
Without all four, your app will not be listed in the default SMS selection dialog.如果没有这四个,您的应用程序将不会列在默认的 SMS 选择对话框中。
If you don't implement all the four requirements, your app won't be listed as a default SMS app.如果您没有实现所有四个要求,您的应用将不会被列为默认 SMS 应用。 Even if your app doesn't support MMS you've to add those to your manifiest file.即使您的应用程序不支持彩信,您也必须将它们添加到您的清单文件中。 It doesn't mean you've to implement activities or services or receivers for them.这并不意味着您必须为它们实现活动或服务或接收器。 Add these to your manifiest file and should get your SMS listed as a default SMS app.将这些添加到您的清单文件中,并应将您的 SMS 列为默认 SMS 应用程序。 Feel free to ignore any lint errors.随意忽略任何 lint 错误。
<!-- BroadcastReceiver that listens for incoming MMS messages -->
<receiver android:name=".MmsReceiver"
android:enabled="@bool/is_kitkat"
android:permission="android.permission.BROADCAST_WAP_PUSH">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>
<!-- Activity that allows the user to send new SMS/MMS messages -->
<activity android:name=".ComposeSmsActivity" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</activity>
<!-- Service that delivers messages from the phone "quick response" -->
<service android:name=".HeadlessSmsSendService"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</service>
On the android P they changed to Role manager.在 android P 上,他们改为角色管理器。
Now it's现在是
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
val roleManager = getSystemService(RoleManager::class.java)
val roleRequestIntent = roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
startActivityForResult(roleRequestIntent, 12)
} else {
val intent = Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName)
startActivity(intent)
}
see: https://stackoverflow.com/a/64136408/14535195见: https : //stackoverflow.com/a/64136408/14535195
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.