Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6_1_0][TIMOB-23429] Android: Nougat file schematics #9041

Merged
merged 3 commits into from May 19, 2017

Conversation

frankieandone
Copy link
Contributor

Test case:

Should not get FileUriExposedException error.

app.js (set up camera):

var win;
function fireCamera() {
	if (Ti.Platform.osname === 'android' || Ti.Platform.osname == "iphone" || Ti.Platform.osname == 'ipad') {
		win.removeEventListener('focus', fireCamera);
	}
	Titanium.Media.showCamera({

		success: function (event) {
			var cropRect = event.cropRect;
			var image = event.media;

			if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
				var imageView = Ti.UI.createImageView({
					width: win.width,
					height: win.height,
					image: event.media
				});
				win.add(imageView);
			}
		},
		cancel: function () {

		},
		error: function (error) {
			if (error.code == Titanium.Media.NO_CAMERA) {
				console.log("device has no camera", error);
			}
			else {
				console.log("unexpected error", error);
			}
		},
		saveToPhotoGallery: true,
		allowEditing: true,
		mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
	});
}
win = Titanium.UI.createWindow({
	title: "classic_app"
});
win.open();
if (Ti.Platform.osname === 'android' || Ti.Platform.osname == "iphone" || Ti.Platform.osname == 'ipad') {
	win.addEventListener('focus', fireCamera);
} else {
	fireCamera();
}

AndroidManifest (add permissions and target Android 7):

<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
	<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="25"/>
        ....
	<uses-permission android:name="android.permission.CAMERA"/>
	<uses-feature android:name="android.hardware.camera2"/>
</manifest>

JIRA: https://jira.appcelerator.org/browse/TIMOB-23429

@frankieandone frankieandone added this to the 6.1.0 milestone May 9, 2017
@frankieandone frankieandone self-assigned this May 9, 2017
@hansemannn
Copy link
Collaborator

@fmerzadyan No reviewer assigned here. Assigning @garymathews as per ticket.

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to the changes request in the main PR here: #8706 (review)

@frankieandone
Copy link
Contributor Author

@garymathews, added requested changes.

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS

TEST CASE
var win = Titanium.UI.createWindow({title: 'TIMOB-23429', backgroundColor: 'gray', layout: 'vertical'}),
    btn = Ti.UI.createButton({title: 'TAKE PICTURE', width: '100%', height: '40dp'}),
    iv = Ti.UI.createImageView({autorotate: true, width: Ti.UI.FILL, height: Ti.UI.FILL});

function takePicture() {
    Titanium.Media.showCamera({
        success: function(e) {
            iv.image = e.media;
            Ti.Media.hideCamera();
        },
        cancel: function() {
            Ti.API.info('canceled');
        },
        error: function(e) {
            Ti.API.error(JSON.stringify(e, null, ' '))
        },
        saveToPhotoGallery: true,
        mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
    });
}

btn.addEventListener('click', function(e) {
    var permissions = ['android.permission.CAMERA',
                       'android.permission.WRITE_EXTERNAL_STORAGE',
                       'android.permission.READ_EXTERNAL_STORAGE'];
    for (var permission of permissions) {
        if (!Ti.Android.hasPermission(permission)) {
            Ti.Android.requestPermissions(permissions, function(e) {
                if (e.success) {
                    takePicture();
                }
            });
            return;
        }
    }
    takePicture();
});

win.add(btn);
win.add(iv);
win.open();

AndroidBuilder.prototype.generateFileProviderPaths = function generateFileProviderPaths(next) {
var xmlDir = path.join(this.buildResDir, 'xml');

if fppFile = path.join(xmlDir, 'file_provider_paths.xml');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if fppFile should be var fppFile. Build fails due to this.

Copy link
Contributor

@jquick-axway jquick-axway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: Pass

@lokeshchdhry
Copy link
Contributor

FR Passed.

The implementation works as expected according to the new permission model for android N.

Studio Ver: 4.9.0.201705170123
SDK Ver: 6.1.0 Local build
OS Ver: 10.12.3
Xcode Ver: Xcode 8.3.2
Appc NPM: 4.2.9
Appc CLI: 6.2.1
Ti CLI Ver: 5.0.13
Alloy Ver: 1.9.11
Node Ver: 6.10.1
Java Ver: 1.8.0_101
Devices: ⇨ google Nexus 6 --- Android 6.0.1
⇨ google Pixel XL --- Android 7.1.1

@lokeshchdhry lokeshchdhry merged commit c124122 into tidev:6_1_X May 19, 2017
NableCommunications pushed a commit to NableCommunications/titanium_mobile_nable that referenced this pull request Aug 9, 2017
Target SDK 24로 설정하면 OS N에서 Ti.Media.showCamera()를 호출하였을 때 Exception 발생하는 현상 수정하는 코드 적
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants