我知道使用Android O,现在我们可以阅读短信验证而无需READ_SMS权限.它可以使用createAppSpecificSmsToken API完成.但我需要一个完整的示例来演示整个SMS验证例程.
解决方法:
没有多少.在SmsManager上调用createAppSpecificSmsToken(),提供PendingIntent.你得到一个String后退,这是一个令牌.如果设备收到带有该令牌的SMS,则运行PendingIntent,触发您指定的任何组件.
/*** copyright (c) 2017 CommonsWare, LLC licensed under the Apache license, Version 2.0 (the "license"); you may not use this file except in compliance with the license. You may obtain a copy of the license at http://www.apache.org/licenses/liCENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implIEd. See the license for the specific language governing permissions and limitations under the license. Covered in detail in the book _The Busy Coder's GuIDe to AndroID Development_ https://commonsware.com/AndroID */package com.commonsware.androID.sms.token;import androID.app.Activity;import androID.app.PendingIntent;import androID.content.Intent;import androID.os.Bundle;import androID.telephony.SmsManager;import androID.Widget.TextVIEw;public class MainActivity extends Activity { @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); SmsManager mgr=SmsManager.getDefault(); String token=mgr.createAppSpecificSmsToken(buildPendingIntent()); TextVIEw tv=(TextVIEw)findVIEwByID(R.ID.text); tv.setText(getString(R.string.msg, token)); } private PendingIntent buildPendingIntent() { return(PendingIntent.getActivity(this, 1337, new Intent(this, ResultActivity.class), 0)); }}
在这里,我在TextVIEw中显示令牌,因此您可以将其键入到其他设备上的SMS客户端,并将令牌绑定到ResultActivity.
您指定的组件(例如,ResultActivity)在其附加组件中接收实际的SMS消息,您可以使用Telephony.Sms.Intents.getMessagesFromIntent()来获取它:
/*** copyright (c) 2017 CommonsWare, LLC licensed under the Apache license, Version 2.0 (the "license"); you may not use this file except in compliance with the license. You may obtain a copy of the license at http://www.apache.org/licenses/liCENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implIEd. See the license for the specific language governing permissions and limitations under the license. Covered in detail in the book _The Busy Coder's GuIDe to AndroID Development_ https://commonsware.com/AndroID */package com.commonsware.androID.sms.token;import androID.app.Activity;import androID.app.PendingIntent;import androID.os.Bundle;import androID.provIDer.Telephony;import androID.telephony.SmsManager;import androID.telephony.SmsMessage;import androID.Widget.TextVIEw;public class ResultActivity extends Activity { @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_main); TextVIEw tv=(TextVIEw)findVIEwByID(R.ID.text); for (SmsMessage pdu : Telephony.Sms.Intents.getMessagesFromIntent(getIntent())) { tv.append(pdu.getdisplayMessageBody()); } }}
总结 以上是内存溢出为你收集整理的没有READ_SMS权限的android sms验证全部内容,希望文章能够帮你解决没有READ_SMS权限的android sms验证所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)