#android #kotlin #gradle
#Android #kotlin #gradle
Вопрос:
Я создал простое телефонное приложение для Android, я разрешил доступ в Интернет в файле манифеста Android в Android Studio, я использую этот метод, чтобы мое приложение можно было использовать для звонков android.Manifest.permission.CALL_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()
}
}
}
это мой main_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 я не использую какую-либо реализацию библиотеки.
Ответ №1:
Добавьте это в свой манифест
<uses-permission android:name="android.permission.CALL_PHONE" />
Комментарии:
1. в классе MainActivity я добавил android.permission. CALL_PHONE, почему я должен снова добавить разрешение
2. Вам нужно добавить его в манифест. и используйте Manifest.permission. CALL_PHONE вместо android. Манифест.разрешение. CALL_PHONE в вашем MainActivity
3. Я был готов добавить вам разрешение, но то же самое не работает.