所以我在这里关注这个Tutorial默认设置我的短信,但由于某种原因,我的代码无效.我试图尽可能多地查看,但所有内容都指向同一个教程或已经过时.我也需要接收器吗?谁能解释我做错了什么?
代码:
@OverrIDeprotected voID onResume(){ super.onResume(); Log.i("MainAcitvity", "On Resume Called"); // Only do these checks/changes on KitKat+, the "mSetDefaultSmsLayout" has its visibility // set to "gone" in the xml layout so it won't show at all on earlIEr AndroID versions. final String myPackagename = getPackagename(); if (Utility.hasKitKat()) { if (Utility.isDefaultSmsApp(this)) { // This app is the default, remove the "make this app the default" layout and // enable message sending components. mSetDefaultSmsLayout.setVisibility(VIEw.GONE); } else { Log.i("MainActivity", "Not Default App"); // Not the default, show the "make this app the default" layout and disable // message sending components. mSetDefaultSmsLayout.setVisibility(VIEw.VISIBLE); button button = (button) findVIEwByID(R.ID.set_default_sms_button); button.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw vIEw) { Log.i("MainActivity", "button Pushed"); //Utility.setDefaultSmsApp(MainActivity.this); Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAulT); intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_name, myPackagename); startActivity(intent); } }); } }}
清单:
<activity androID:name=".MainActivity" androID:label="@string/app_name" > <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> <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>
解决方法:
为了使您的应用程序有资格被选为默认消息传递应用程序(就系统而言),您必须列出清单中显示的所有组件,如该博文中所示,这些组件的类是否实际存在或不.
<manifest> ... <application> <!-- broadcastReceiver that Listens for incoming SMS messages --> <receiver androID:name=".SmsReceiver" androID:permission="androID.permission.broADCAST_SMS"> <intent-filter> <action androID:name="androID.provIDer.Telephony.SMS_DEliVER" /> </intent-filter> </receiver> <!-- broadcastReceiver that Listens for incoming MMS messages --> <receiver androID:name=".MmsReceiver" 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> </application></manifest>
由于系统仅检查应用程序的清单以确定它是否可以充当默认消息传递应用程序,因此并非所有这些组件的类都必须存在才能使您的应用程序显示在默认选择列表中.这对于学习和测试很有用,但是,显然,如果您的应用程序要充当用户的默认消息传递客户端,它应该完全实现所有指定的组件.
如果您打算执行任何与SMS / MMS相关的任务,您还需要相关权限.虽然系统在确定符合条件的默认应用程序候选者时显然不会检查这些,但以下权限对于其相应的 *** 作是必需的:
<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" />
如果在尝试执行给定 *** 作时缺少SEND_SMS,READ_SMS或WRITE_SMS权限,则将抛出SecurityException.但是,如果您错过了RECEIVE_ *权限,那么您的应用程序将无法提供相关的广播,并且在测试这些功能时似乎没有任何事情发生.
总结以上是内存溢出为你收集整理的android默认制作默认短信应用程序全部内容,希望文章能够帮你解决android默认制作默认短信应用程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)