我创建了一个简单的相机应用程序.除了Android 4.4之外,它在Android的所有版本中都能正常运行.当我从相机应用程序拍照时,我收到以下错误.
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MEDIA_MOUNTED from pid=26089, uid=10120
Run Code Online (Sandbox Code Playgroud)
出现错误:
在以下地方:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
Run Code Online (Sandbox Code Playgroud)
如何解决KITKAT的这个问题?
让我知道!
谢谢!
是否有任何插件为cordova(android)刷新画廊?
使用cordova插件捕获视频,cordova-plugin-media-capture它将视频保存到默认的SD卡路径(图库).
现在我将文件从sdcard路径移动到我的应用程序目录路径(com.test.app).
问题:移动文件后,仍然有一个带名称的视频缩略图No thumbnail.当我点击缩略图时,这会显示一个警告The file can not be reproduced,因为它已从图库路径移动到应用程序路径.如果我重新启动手机,则没有视频缩略图,因为它刷新了SD卡/图库.我想要的是移动文件后刷新库.
移动文件的代码
使用的插件: cordova-plugin-file
var fileURI="file:/storage/emulated/0/DCIM/Camera/VID_20161022_121221.mp4";
var newFileUri='file:///mnt/sdcard/Android/data/com.test.app/myvideo/';
var newFileName='uservideoname.mp4';
window.resolveLocalFileSystemURL(fileURI,
function (fileEntry) {
window.resolveLocalFileSystemURL(newFileUri,
function (dirEntry) {
// move the file to a new directory and rename it
fileEntry.moveTo(dirEntry, newFileName, function () {
// successfully moved
},
function (e) {
console.log(e);
});
},
function (e) {
console.log(e);
});
},
function (e){
console.log(e);
});
}
Run Code Online (Sandbox Code Playgroud) testButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v)
{
imageView.setImageBitmap(Bitmap);
imageView.buildDrawingCache();
Bitmap bm =imageView.getDrawingCache();
Intent imageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "Punch");
imagesFolder.mkdirs();
String fileName = "image" + ".jpg";
File output = new File(imagesFolder, fileName);
Uri uriSavedImage = Uri.fromFile(output);
imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
OutputStream fos = null;
try {
fos = getContentResolver().openOutputStream(uriSavedImage);
bm.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{}
}
});
Run Code Online (Sandbox Code Playgroud)
首先,我从SD卡检索图像到分辨率的图像视图(640 x 480).然后我再次将图像从图像视图保存到SD卡.但保存的图像分辨率为(188x113).任何人都可以建议我如何以相同的分辨率保存.任何建议都会很明显.
我在onClick上使用onClick来捕获图像.
PictureCallback myPictureCallback_JPG = new PictureCallback() {
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
FileOutputStream outStream = null;
try {
// Write to SD Card
outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", System.currentTimeMillis()));
outStream.write(arg0);
outStream.close();
Toast.makeText(Photo.this, "Image Saved to SD Card", Toast.LENGTH_SHORT).show();
System.out.println();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
camera.startPreview();
}};
Run Code Online (Sandbox Code Playgroud)
图像保存在SD卡中.然后用户单击"发送"按钮并打开布局,在"单击ImageView"上打开图像库并单击特定图像,将选择URI.
imageAttachPhoto = (ImageView)findViewById(R.id.imageViewPhotoOne);
imageAttachPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);
} …Run Code Online (Sandbox Code Playgroud) 我已经尝试过这段代码,但它没有正常工作.
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent, Manifest.permission.WRITE_SECURE_SETTINGS);
Run Code Online (Sandbox Code Playgroud)
得到此错误:
java.lang.RuntimeException:无法启动活动ComponentInfo {com.setting/com.setting.activity.TraceLocationActivity}:java.lang.SecurityException:Permission Denial:不允许从pid = 28258发送广播android.location.GPS_ENABLED_CHANGE,uid Android.app.A活动时,Android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)的android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2773)上的android.app.ActivityThread.- wrap12(ActivityThread.java)= 10395 = 10395 .ActivityThread $ H.handleMessage(ActivityThread.java:1567)在android.app.Loper.loop(Looper.java:156)的android.app.Handler.dispatchMessage(Handler.java:105)android.app.ActivityThread. main(ActivityThread.java:6523)位于com.android.internal的com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:942)的java.lang.reflect.Method.invoke(Native Method)中. os.ZygoteInit.main(ZygoteInit.java:832)引起:java.lang.SecurityException:Permission Denial:不允许发送广播andr oid.location.GPS_ENABLED_CHANGE来自pid = 28258,uid = 10395,android.os.Parcel.readException(Parcel.java:1665),位于android.app.ActivityManagerProxy的android.os.Parcel.readException(Parcel.java:1618). broadcastIntent(ActivityManagerNative.java:3533)位于android.content.ContextIrap.sendBroadcast(ContextImpl.java:1012)的android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:426)位于com.setting.activity.TraceLocationActivity.onCreate(TraceLocationActivity) .java:46)在android.app.Anstrumentation.callActivityOnCreate(Instrumentation.java:1123)android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2746)的android.app.Activity.performCreate(Activity.java:6915)在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)的android.app.ActivityThread.-wrap12(ActivityThread.java)android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1567)在android.os .andand.dispatchMessage(Handler.java:105)在android.os.Looper.loop(Looper.java:156)at和 roid.app.ActivityThread.main(ActivityThread.java:6523)位于com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:942)的java.lang.reflect.Method.invoke(Native Method)中com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)