udacity / AdvancedAndroid_Emojify

139 stars 452 forks source link

TLIB.02-Solution-DetectFaces #23

Open ghost opened 7 years ago

kahraman-mustafa commented 6 years ago

Hi, I have gotten two error while working on this branch and found solutions from stackoverflow. Maybe some other one faces the same problem, I want to share my solutions. My emulator is my own phone running Android 4.4.2. The logcat error and the corresponding solutions are like the below:

ERROR 1: java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord ... SOLUTION 1 (FROM): https://stackoverflow.com/questions/24467696/android-file-provider-permission-denial . Applying the solution from the link as in the below in the launchCamera() method in the MainActivity.java:

takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);

// Solution is found in stackoverflow "https://stackoverflow.com/questions/24467696/android-file-provider-permission-denial"
List<ResolveInfo> resInfoList = this.getPackageManager().queryIntentActivities(takePictureIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
   String packageName = resolveInfo.activityInfo.packageName;
   this.grantUriPermission(packageName, photoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}

// Launch the camera activity
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);

Answer by https://stackoverflow.com/users/1069884/limlim

ERROR 2: android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection ... SOLUTION 2 (FROM): https://stackoverflow.com/questions/13765122/android-emulator-spams-logcat-with-service-com-android-exchange-exchangeservice .

A simpler fix is to disable "Exchange Services" in the emulated device under Settings : Apps : All (you may need to swipe over to see the "All" tab) Answer by https://stackoverflow.com/users/42619/nuthatch

ADDITION: I have also noticed that it is required to rotate my device 90 degree reverse clockwise when taking photo in order to get true portrait image and be the face detected. Otherwise the face is not detected.