In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces Android how to hang up the phone related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe everyone will have some gains after reading this Android how to hang up the phone article, let's take a look at it.
1. Android Dynamic Request Permission
First, you need to statically apply for phone permissions in AndroidManifest.xml, otherwise you cannot dynamically apply for permissions. The following code positions cannot be misplaced (outside the application):
Then, write the logic of dynamic permission application in java code (this is the official website)
public void requestPower() {//Determine whether permission has been granted if (ContextCompat.checkSelfPermission(this, Manifest.permission. above phone permission character) != PackageManager.PERMISSION_GRANTED) { //This method returns true if the application previously requested this permission but the user refused the request. if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest. permission. above telephone permission character)) {//Here you can write a dialog box to explain to the user why you want to apply for permission, and in the dialog box confirm the key to apply for permission again. It returns false if the user selects "Don't ask again." } else { //Apply permission. The string array contains one or more permissions to apply for. 1 is the return parameter of the permission application result. You can find the application result in onRequestPermissionsResult. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission. Phone characters above,}, 1); } 2. Create an AIDL file ITelephony package name must be (com.android.internal.telephony)// ITelephony.aidl package com.android.internal.telephony; / Declare any non-default types here with import statements interface ITelephony { boolean endCall(); void answerRingCall (); }3. Write java code to hang up the phone private void endCall() { try { //Get the hidden API through reflection, and get the Class object of the hidden class Class clazz = Class.forName("android.os.ServiceManager"); //Get Method object Method method = clazz.getMethod("getService", String.class); //call method to get iBinder object IBinder ibinder = (IBinder) method.invoke(null, Context.TELEPHONY_SERVICE); ITelephony iTelephony = ITelephony.Stub.asInterface(ibinder); iTelephony.endCall();//End call } catch (Exception e) { e.printStackTrace(); } }
Remember to add phone privileges dynamically! Otherwise, hanging up the phone would not be possible.
The content of this article on "Android how to hang up the phone" is introduced here, thank you for reading! I believe everyone has a certain understanding of the knowledge of "Android how to hang up the phone." If you still want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.