The*_*Man 6 android message android-4.4-kitkat
我创建了一个SMS应用程序,可以正确显示所有消息,还BroadcastReceiver有助于在到达时让我知道新消息.
使用URI的帮助,content://mms-sms/conversations?simple=true我能够检索消息.
即使在KitKat上也能正常工作.我可以发送短信,阅读短信,但我无法删除短信,因为我的应用程序不是默认的短信应用程序.
如何提示用户使应用程序默认?我看了这个博客:
我尝试了它上面给出的代码,但我没有看到任何区别?我在这里错过了什么吗?
这是代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
等待你的回复!谢谢!
我通过在清单中输入以下内容来解决.
最重要的部分我们应该使用一切,包括MMS部分,如果不是它将无法正常工作.
<!-- 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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1448 次 |
| 最近记录: |