0

I'm trying to figure out permission in android. I have written a code that allows you to access the gallery with images. I didn't add any permission in the manifest. But from the app, I can access the gallery, although I shouldn't have (tried on an emulator and on a physical device).

Then I tried to do the same for a phone call. Here without <uses-permission android:name="android.permission.CALL_PHONE" /> an exception is thrown.

Can't figure out why I can access the gallery

import android.content.Intent

import android.net.Uri
import android.os.Bundle
import androidx.activity.result.ActivityResultCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import ru.artrostudio.testgalery.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var uri: Uri

    private lateinit var mBinding:ActivityMainBinding
    var resultLauncher =registerForActivityResult(
        ActivityResultContracts.GetContent(),
        ActivityResultCallback {
          println("${it.toString()}")
            uri=it
           mBinding.imageView.setImageURI(uri)
        }
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView( mBinding.root)

        mBinding.button.setOnClickListener {
            resultLauncher.launch("image/*")


        }

        mBinding.button2.setOnClickListener { call() }
    }


    private fun call()
    {
        var tel="tel:0000000"
        var intent=Intent(Intent.ACTION_CALL)
        intent.data=Uri.parse(tel)
        startActivity(intent)
    }
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <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/Theme.TestGalery">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>
Lenoarod
  • 3,074
  • 13
  • 22
Staf
  • 9
  • 1

0 Answers0