简体   繁体   中英

Android permission for camera and Internet

In Android, I remember that it was mandatory to request permission(s) to use the camera or to access the Internet in an app.

But I did a small test in which I did not request any of the above permissions and I expected my test app to crash and burn.

But this did not happen!!

I was able to use the camera and access the Internet without requesting for permissions, and I've tested on 3 devices, all with different versions of Android.

Here is the code:

public class MainActivity extends Activity implements View.OnClickListener
{
    private int cameraCode = 0;
    private Button start_cam;
    private Button start_internet;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        start_cam = (Button) findViewById(R.id.camera);
        start_internet = (Button) findViewById(R.id.internet);

        start_cam.setOnClickListener(this);
        start_internet.setOnClickListener(this);
    }

    @Override
    public void onClick(View v)
    {
        switch(v.getId())
        {
            case R.id.camera:
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, cameraCode);
                break;
            case R.id.internet:
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.imdb.com"));
                startActivity(browserIntent);
                break;
        }
    }
}

the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.permissions.linux.android">

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="16" />

    <application
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">

        <activity
            android:name="com.permissions.linux.androi.android.MainActivity"
            android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


    </application>

</manifest>

The question is, why didn't it crash?

I was able to use the camera and access the Internet without requesting for permissions

No, you were not. You were able to ask other applications "to use the camera and access the Internet" on your behalf. Your application did not directly use the camera, and your application did not directly access the Internet. The other applications that you linked to will need the CAMERA and INTERNET permissions to do their jobs. While sometimes you may need to hold a certain permission even to get a third-party app to do something for you, that is not needed to take a picture or view a Web page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM