我创建了一个可以正确显示所有消息的 SMS 应用程序,还创建了一个 BroadcastReceiver
帮助我在收到新消息时通知我。
使用 URI 的帮助 content://mms-sms/conversations?simple=true
我能够检索消息。
即使在 KitKat 上也能正常工作。我可以发送短信、阅读短信,但我无法删除短信,因为我的应用程序不是默认的短信应用程序。
问题:
如何提示用户将应用设为默认?我看了this blog :
我试过上面给出的代码,但没有发现任何区别?我在这里遗漏了什么吗?
代码如下:
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= 19)
{
final String myPackageName = getPackageName();
if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName))
{
// App is not default.
// Show the "not currently set as the default SMS app" interface
View viewGroup = findViewById(R.id.not_default_app);
viewGroup.setVisibility(View.VISIBLE);
// Set up a button that allows the user to change the default SMS app
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent intent =
new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
myPackageName);
startActivity(intent);
}
});
}
else
{
// App is the default.
// Hide the "not currently set as the default SMS app" interface
View viewGroup = findViewById(R.id.not_default_app);
viewGroup.setVisibility(View.GONE);
}
}
等待您的回复! 谢谢!
最佳答案
我通过在 list 中输入以下内容来解决。
最重要的部分我们应该使用一切,包括彩信部分,如果没有它就无法工作。
<!-- 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>
关于android - 如何为 KitKat 设置默认短信提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21212690/