我制作了一个android sms应用程序,我发送和接收短信作为Android消息应用程序这样做。现在我已将目标设置为4.4(Android KitKat版本),但Android KitKat具有新的“默认消息”应用程序设置,用户可以一次选择一个应用程序进行消息传递。我按照this site中的步骤选择我的短信应用程序选项作为默认应用程序,但在设置中我的应用程序从未出现在选择默认消息应用程序的弹出窗口中。
以下是我从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();
}
}
我还在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>
更新
注意:我在模拟器上测试... 完成所有步骤后,我只会看到Android的默认消息传递应用程序,如下图所示。任何类型的帮助将不胜感激。在此先感谢。
答案 0 :(得分:12)
您发布的instructions是正确的 - 问题是您必须实施所有所需的功能:
在广播接收器中,包含SMS_DELIVER_ACTION
(“android.provider.Telephony.SMS_DELIVER
”)的意图过滤器。广播接收器还必须要求BROADCAST_SMS权限。
这允许您的应用直接接收传入的短信。
在广播接收器中,包含MIME类型为“WAP_PUSH_DELIVER_ACTION
”的android.provider.Telephony.WAP_PUSH_DELIVER
(“application/vnd.wap.mms-message
”)的意图过滤器。广播接收器还必须具有BROADCAST_WAP_PUSH权限。
这样,您的应用就可以直接接收传入的彩信。
在您投放新邮件的活动中,包含ACTION_SENDTO
(“android.intent.action.SENDTO
”)的方案过滤器,其中包含模式,sms:
,smsto:
,{{ 1}}和mms:
。
这允许您的应用从其他想要传递消息的应用中接收意图。
在服务中,包含mmsto:
(“ACTION_RESPONSE_VIA_MESSAGE
”)的意图过滤器,其中包含模式android.intent.action.RESPOND_VIA_MESSAGE
,sms:
,smsto:
,和mms:
。此服务还必须具有mmsto:
权限。
如果没有全部四个,您的应用将不会列在默认的短信选择对话框中。
答案 1 :(得分:4)
如果您未实施所有这四项要求,您的应用将不会被列为默认短信应用。即使您的应用不支持彩信,您也可以将其添加到最明显的文件中。它并不意味着您要为它们实现活动或服务或接收器。将这些添加到您最明显的文件中,并将您的短信列为默认短信应用程序。随意忽略任何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>
答案 2 :(得分:0)
在 android P 上,他们改为角色管理器。
现在是
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)
}