In android, I remember that it was mandatory to request permission to use the Camera or to use the internet connection in a 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 & burn.
But this did not happen!!
I was able to use the cammera and the internet without requesting for permissions, and I've tested on 3 devices all with different version 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 crashed??
0 comments:
Post a Comment