Android 电话API不起任何作用
我为android制作了一个简单的电话应用程序,我在android studio上的android清单文件中创建了互联网权限,我使用此方法使我的应用程序可以用于调用Android 电话API不起任何作用,android,kotlin,gradle,Android,Kotlin,Gradle,我为android制作了一个简单的电话应用程序,我在android studio上的android清单文件中创建了互联网权限,我使用此方法使我的应用程序可以用于调用android.Manifest.Permission.CALL\u PHONE 但当我运行代码时,什么也没发生 这是第一节课: class MainActivity : AppCompatActivity() { val mobno: String = "1234567890" val REQU
android.Manifest.Permission.CALL\u PHONE
但当我运行代码时,什么也没发生
这是第一节课:
class MainActivity : AppCompatActivity() {
val mobno: String = "1234567890"
val REQUEST_PHONE_CALL = 1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val call = findViewById<Button>(R.id.phone_call)
call.setOnClickListener {
if (ActivityCompat.checkSelfPermission(
this,
android.Manifest.permission.CALL_PHONE
) != PackageManager.PERMISSION_GRANTED
) {
}
}
}
private fun makecall() {
val intent = Intent(Intent.ACTION_CALL, Uri.fromParts("tel", mobno, null))
startActivity(intent)
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>,
grantResults: IntArray
) {
if (requestCode == REQUEST_PHONE_CALL) {
makecall()
}
}
}
class MainActivity:AppCompatActivity(){
val mobno:String=“1234567890”
val请求\电话\呼叫=1
重写创建时的乐趣(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val call=findViewById(R.id.phone\U call)
call.setOnClickListener{
如果(ActivityCompat.checkSelfPermission(
这
android.Manifest.permission.CALL\u电话
)!=已授予PackageManager.PERMISSION\u权限
) {
}
}
}
私人娱乐电话(){
val intent=intent(intent.ACTION_调用,Uri.fromParts(“tel”,mobno,null))
星触觉(意图)
}
覆盖onRequestPermissionsResult(
请求代码:Int,
权限:数组,
格兰特结果:因塔雷
) {
if(requestCode==请求电话){
makecall()
}
}
}
这是我的主要_activity.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/phone_call"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:text="Place Call" />
</LinearLayout>
这是我的舱单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.telephoneappkotlin">
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在我的graddle中,我不使用任何库实现。将其添加到清单中
<uses-permission android:name="android.permission.CALL_PHONE" />
将其添加到您的清单中
<uses-permission android:name="android.permission.CALL_PHONE" />
在MainActivity类中,我添加了android.permission.CALL\u PHONE,为什么我必须再次添加权限?您需要在清单中添加权限。在MainActivity中使用Manifest.permission.CALL_PHONE而不是android.Manifest.permission.CALL_PHONE我已准备好向您添加权限,但它同样不起作用。在MainActivity类中,我添加了android.permission.CALL_PHONE,为什么我必须再次添加权限?如果您需要将其添加到清单中。并在MainActivity中使用Manifest.permission.CALL_PHONE而不是android.Manifest.permission.CALL_PHONE。我已准备好向您添加权限,但它同样不起作用。