我曾經以爲來訪問你的應用程序相機和畫廊,許可是必要的,特別是在棉花糖以上許可在運行時都需要待辦事項應用程序需要許可打開相機和畫廊
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
但我我認爲我錯了,因爲我的應用程序未經許可也工作。我有Myapp - >權限。沒有授予權限。 但它怎麼能工作。下面是我的畫廊簡單的代碼:
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
takePhoto ();
}
public void takePhoto () {
Intent intent = new Intent ();
intent.setType ("image/*");
intent.setAction (Intent.ACTION_GET_CONTENT);//
startActivityForResult (Intent.createChooser (intent, "Select Image"), SELECT_IMAGE);
}
public void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult (requestCode, resultCode, data);
if (requestCode == SELECT_IMAGE) {
if (resultCode == Activity.RESULT_OK) {
if (data != null) {
try {
Log.e ("INSIDE------", "onActivityResult: ");
Bitmap bitmap = MediaStore.Images.Media.getBitmap (this.getContentResolver (), data.getData ());
} catch (IOException e) {
e.printStackTrace ();
}
}
} else if (resultCode == Activity.RESULT_CANCELED) {
Toast.makeText (this, "Cancelled", Toast.LENGTH_SHORT).show ();
}
}
}
和攝像頭這是代碼:
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
takePhoto ();
}
public void takePhoto() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, TAKE_PICTURE);
}
我的清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.utkarshshukla.fragmentpractice">
<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>
我gradle這個
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.utkarshshukla.fragmentpractice"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:26.+'
testCompile 'junit:junit:4.12'
}
這兩個代碼的作品,我沒有在清單中聲明任何權限。雖然在聲明相機的清單許可後,它崩潰說需要權限,但沒有在清單中寫入,它的工作原理爲什麼它的工作原理(在圖庫中未嘗試過)。在開發人員網站上他們提到要獲得許可,但沒有提及如果發生什麼情況未採取任何許可。
問題是,爲什麼它是工作沒有權限
感謝
你可以舉一個例子,說明如何使用相機而不需要其他應用程序來完成它,並只通過我們的應用程序來完成工作。 – JSONParser
@UkkarshShukla - 您想要關注[構建相機應用培訓](https://developer.android.com/guide/topics/media/camera.html#custom-camera) – ianhanniballake