我正在尝试获取传出号码,但在oreo之前,代码工作得非常好,但在使用oreo代码的设备中无效.
public class IncomingbroadCastReceiver extends broadcastReceiver { Context context; WhatsAppContacts requiredContact; List<String> messages = new ArrayList<>(); String callername=""; Realm realm; String outgoingNumber = ""; @OverrIDe public voID onReceive(final Context context, final Intent intent) { Log.d("Search","onReceive"); this.context = context; realm = Realm.getDefaultInstance(); TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); telephony.Listen(new PhonestateListener(){ @OverrIDe public voID onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); Log.d("Search","above Ringing"+state); if(state == TelephonyManager.CALL_STATE_RINGING){ SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("number", incomingNumber); Log.d("Ringing", incomingNumber); editor.apply(); Log.d("Search","insIDe call state changed"); initialiseAndStartService(); } else if (intent.getAction().equals("androID.intent.action.NEW_OUTGOING_CALL")){ //Outgoing call String number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); Log.i("tag","Outgoing number : "+number); if(number!=null){ SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("number", number); editor.apply(); Log.d("Search","insIDe call state changed"); initialiseAndStartService(); } } } },PhonestateListener.ListEN_CALL_STATE); }}
在奥利奥之前的版本中,它的工作完全正常.但在奥利奥无法获得传出号码.
解决方法:
奥利奥有一个限制.您无法在清单中注册隐式广播,而NEW_OUTGOING_CALL是隐式广播.当您的应用程序处于活动状态且用户正在与其进行交互时,您才能进行该广播工作.
你可以找到更多信息here
以上是内存溢出为你收集整理的java – 在奥利奥,我无法获得传出号码全部内容,希望文章能够帮你解决java – 在奥利奥,我无法获得传出号码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)