native.js调用Android拍照并保存至相册

 

保存至相册:plus.gallery.save( path, successCB, errorCB );

参数:

path : ( String ) 必选 要保存到系统相册中的文件文件地址

succesCB: ( GallerySuccessCallback ) 必选 保存文件到系统相册中成功的回调函数

errorCB: ( GalleryErrorCallback ) 可选 保存文件到系统相册中失败的回调函数

// 拍照
function captureImage(){
	var cmr = plus.camera.getCamera();
	var res = cmr.supportedImageResolutions[0];
	var fmt = cmr.supportedImageFormats[0];
	cmr.captureImage( 
		function( path ){
            //拍照成功回调
            console.log(path);
		    saveGallery(path);  //保存图片至相册
		},
		function( error ) {
			alert( "Capture image failed: " + error.message );
		},
		{resolution:res,format:fmt,filename: "_doc/election/",}
	);
}


//保存图片至手机相册
function saveGallery(filePath){
	plus.gallery.save( filePath, function () {
		alert( "保存图片到相册成功" );
	} );
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在 uni-app 中,可以通过 uni.requireNativePlugin 方法调用 native.js 中的方法。具体步骤如下: 1. 在 uni-app 项目中创建 Native 模块,用于调用 native.js 中的方法: ```javascript const nativeModule = uni.requireNativePlugin("NativeModule"); ``` 2. 在 Native 模块中定义调用 startForeground 方法的函数: ```javascript function startForeground() { nativeModule.startForeground(); } ``` 3. 在 native.js 中实现 startForeground 方法,同样需要导入相关的 Android 类: ```javascript const Context = require("@android/context"); const Notification = require("@android/app/Notification"); const NotificationManagerCompat = require("@android/app/NotificationManagerCompat"); const NotificationChannel = require("@android/app/NotificationChannel"); function startForeground() { const service = getContext().getService(); const channel = new NotificationChannel("channel_id", "channel_name", NotificationManagerCompat.IMPORTANCE_HIGH); const notificationManager = NotificationManagerCompat.from(Context); const notification = new Notification.Builder(Context, "channel_id") .setSmallIcon(android.R.drawable.ic_dialog_info) .setContentTitle("Foreground Service") .setContentText("Service is running in foreground") .build(); service.startForeground(1, notification); } ``` 4. 在 Native 模块中调用 startForeground 方法: ```javascript function startForeground() { nativeModule.startForeground(); } ``` 这样就可以通过 uni-app 调用 native.js 中的 startForeground 方法开启前台服务了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值