//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Create a button 1/3 of screen width and 1/10 screen height.
btn = app.CreateButton( "Send Intent", 0.3, 0.1 );
btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );
//Create a text label and text boxt.
txt = app.CreateText( "Intent Data:" );
lay.AddChild( txt );
txt1 = app.CreateText( "", 0.95, 0.6 , "left,multiline" );
txt1.SetBackColor( "#ff222222" );
txt1.SetTextSize( 18 );
lay.AddChild( txt1 );
//Add layout to app.
app.AddLayout( lay );
}
//Called when user touches our button.
function btn_OnTouch()
{
// var packageName = "com.android.camera";
// var className = "";
// var action = "MediaStore.ACTION_IMAGE_CAPTURE";
// var category = null;
// var uri = "myfr...@gmail.com";
// var type = "message/rfc822";
// var extras = [
// {name:"android.intent.extra.EMAIL", type:"list", value:"fr...@gmail.com"},
// {name:"android.intent.extra.SUBJECT", type:"string", value:"My subject"},
// {name:"android.intent.extra.TEXT", type:"string", value:"Hello!"}
// ];
// extras = JSON.stringify( extras );
app.SendIntent(null,null,'android.media.action.IMAGE_CAPTURE',null,null,null,null,null, myCallback);
}
function myCallback(e)
{
app.ShowPopup(e);
}
function OnData( isStartUp )
{
//Display intent data.
var intent = app.GetIntent();
if( intent )
{
//Extract main data.
var s = "action: " + intent.action + "\n";
s += "type: " + intent.type + "\n";
s += "data: " + intent.data + "\n\n";
//Extract extras.
s += "extras:\n";
for( var key in intent.extras )
s += key+": "+intent.extras[key] + "\n";
txt1.SetText( s );
}
}
// Sent Intent
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (i.resolveActivity(getPackageManager()!=null)){
try{
cacheFile = createTempFile("img",".jpg",getCacheDir());
cacheFile.setWritavle(true,false);
}catch(IOException e){}
if(cacheFile != null){
i.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(cacheFile));
startActivityForResult(i,REQUEST_IMAGE_CAPTURE);
}
}
// Receive Intent
protected void onActivityResult(int requestCode,int resultCode,Intent data){
if(requestCode != RESULT_OK){
return;
}
if(requestCode == REQUEST_IMAGE_CAPTURE){
try{
File output = getImageFile();
if(output != null && cacheFile != null){
copyFile(cacheFile,output);
//Process image file stored at output
cacheFile.delete();
cacheFile=null;
}
}catch(IOException e){}
}
}
Regards,
Sankarshan
I finished the plugin ( including TakePicture function you need) ! Tomorrow morning ( now here are the 22 o'clock ) I finish the documentation and release the plugin and the demo application ...
Stay tuned! :)
/**
* Get the URI of the selected image from {@link #getPickImageChooserIntent()}.<br/>
* Will return the correct URI for camera and gallery image.
*
* @param data the returned data of the activity result
*/
public Uri getPickImageResultUri(Intent data) {
boolean isCamera = true;
if (android.os.Build.VERSION.SDK_INT >= 23) {
isCamera = (data != null && data.getClipData() != null) ? false : true;
} else {
if (data != null) {
String action = data.getAction();
isCamera = action != null && action.equals(MediaStore.ACTION_IMAGE_CAPTURE);
}
}
return isCamera ? getCaptureImageOutputUri() : data.getData();
}Add permisson to the AndroidManifest.xml and replace the getPickImageResultUri method.
<uses-permission android:name="android.permission.CAMERA"/>
finded here : https://github.com/ArthurHub/Android-Image-Cropper/issues/26
If you want try, put this file (renamed as you have done before) into DroidScript/Plugins folder, then restart DroidScript (plugon will be replaced)
I waiting for news...
_AddPermissions() can be placed at the start of the plugin .inc file or in the app's own code.
public class MarshMallowPermission {
public static final int RECORD_PERMISSION_REQUEST_CODE = 1;
public static final int EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE = 2;
public static final int CAMERA_PERMISSION_REQUEST_CODE = 3;
Activity activity;
public MarshMallowPermission(Activity activity) {
this.activity = activity;
}
public boolean checkPermissionForRecord(){
int result = ContextCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO);
if (result == PackageManager.PERMISSION_GRANTED){
return true;
} else {
return false;
}
}
public boolean checkPermissionForExternalStorage(){
int result = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (result == PackageManager.PERMISSION_GRANTED){
return true;
} else {
return false;
}
}
public boolean checkPermissionForCamera(){
int result = ContextCompat.checkSelfPermission(activity, Manifest.permission.CAMERA);
if (result == PackageManager.PERMISSION_GRANTED){
return true;
} else {
return false;
}
}
public void requestPermissionForRecord(){
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.RECORD_AUDIO)){
Toast.makeText(activity, "Microphone permission needed for recording. Please allow in App Settings for additional functionality.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(activity,new String[]{Manifest.permission.RECORD_AUDIO},RECORD_PERMISSION_REQUEST_CODE);
}
}
public void requestPermissionForExternalStorage(){
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)){
Toast.makeText(activity, "External Storage permission needed. Please allow in App Settings for additional functionality.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(activity,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE);
}
}
public void requestPermissionForCamera(){
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA)){
Toast.makeText(activity, "Camera permission needed. Please allow in App Settings for additional functionality.", Toast.LENGTH_LONG).show();
} else {
ActivityCompat.requestPermissions(activity,new String[]{Manifest.permission.CAMERA},CAMERA_PERMISSION_REQUEST_CODE);
}
}
}...
MarshMallowPermission marshMallowPermission = new MarshMallowPermission(this);
...
public void getPhotoFromCamera() {
if (!marshMallowPermission.checkPermissionForCamera()) {
marshMallowPermission.requestPermissionForCamera();
} else {
if (!marshMallowPermission.checkPermissionForExternalStorage()) {
marshMallowPermission.requestPermissionForExternalStorage();
} else {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File mediaStorageDir = new File(
Environment.getExternalStorageDirectory()
+ File.separator
+ getString(R.string.directory_name_corp_chat)
+ File.separator
+ getString(R.string.directory_name_images)
);
if (!mediaStorageDir.exists()) {
mediaStorageDir.mkdirs();
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
try {
mediaFile = File.createTempFile(
"IMG_" + timeStamp, /* prefix */
".jpg", /* suffix */
mediaStorageDir /* directory */
);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mediaFile));
startActivityForResult(takePictureIntent, PICK_FROM_CAMERA);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}