How should I use onActivityResult method in LL?

How should I use onActivityResult method in LL?

I used startActivityForResult(Intent, requestCode) to start the activity but I can’t find out a way to use correctly onActivityResult(requestCode, resultCode, data) in Lightning Launcher.

Someone could help me please?

Here is the documentation: http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int,int,android.content.Intent)

]]>

10 Commentsto How should I use onActivityResult method in LL?

  1. Anonymous says:

    < ![CDATA[

    TrianguloY  A lot of time wasted to search an outside solution, when it was inside LL xD



    Anyway, it says: – the “receiver” script is called with the following parameters set – it means that the parameters are setted as Tag?

    ]]>

  2. Anonymous says:

    < ![CDATA[

    No. It means that a variable named ‘tag’ is available with that data

    ]]>

  3. Anonymous says:

    < ![CDATA[

    No wait. I wrote it wrong.


    In the script you will have three already available variables:


    resultCode, data, token


    You can use them directly, for example “alert(data)”

    ]]>

  4. Anonymous says:

    < ![CDATA[

    TrianguloY perfect ^_^ thanks for your usefull help!!

    ]]>

  5. Anonymous says:

    < ![CDATA[

    Unfortunately it seems like the script receiver is not launched after the activity ends, rather it seems that the activity not ends at all!



    This is the Intent that I used:


    var intent= new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);



    And this is the method: context.startActivityForResult(Intent.createChooser(intent,”Choose an image picker”),script);



    After I choosed the image it goes back to LL and I noticed that appear a blank item in the same container where the script has launched.



    Pierre Hébert​??


    ]]>

  6. Anonymous says:

    < ![CDATA[

    I don’t know what this blank item is! Could it be that it is created by another script and the wrong script is called on activity result ?

    ]]>

  7. Anonymous says:

    < ![CDATA[

    I’m making a small video.


    Anyway, this is the script were the intent is launched (the intent is launched in the imageView click listener):



    //=======================


    //======= Classes =======


    //=======================



    LL.bindClass(“android.app.AlertDialog”);


    LL.bindClass(“android.content.DialogInterface”);


    LL.bindClass(“android.view.View”);


    LL.bindClass(“android.view.ViewGroup”);


    LL.bindClass(“android.view.Gravity”);


    LL.bindClass(“android.widget.LinearLayout”);


    LL.bindClass(“android.widget.TextView”);


    LL.bindClass(“android.widget.EditText”);


    LL.bindClass(“android.text.InputType”);


    LL.bindClass(“android.widget.ImageView”);


    LL.bindClass(“android.graphics.BitmapFactory”);



    LL.bindClass(“android.app.Activity”);


    //LL.bindClass(“android.content.Intent”);


    LL.bindClass(“android.provider.MediaStore”);



    eval(LL.getScriptByName(“Get_pixels”).getText());


    eval(LL.getScriptByName(“[lib]cont&metrics”).getText());



    var context= LL.getContext();


    var style= LL.getVariables().getInteger(“sysStyle”);


    var script= LL.getScriptByName(“imageActivityResult”);



    //=======================


    //======= Objects =======


    //=======================



    var desk= LL.getCurrentDesktop();


    var acName= LL.getItemById(7929858);


    var acMail= LL.getItemById(7929857);


    var acAvatar= LL.getItemById(7077894);



    //======================


    //======= Params =======


    //======================



    var layPad= getPixels(16);


    var imgPad= getPixels(50);


    var textPad= getPixels(10);



    var textColor= (style!=AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)?0xfff1f1f1 : 0xff202020;



    //======================


    //======= Layout =======


    //======================




    mainLayout= new LinearLayout(context);


    mainLayout.setOrientation(LinearLayout.VERTICAL);



    var layout= new LinearLayout(context);


    layout.setOrientation(LinearLayout.VERTICAL);


    layout.setPadding(layPad,layPad,layPad,layPad);



    var imgLayout= new LinearLayout(context);


    imgLayout.setGravity(Gravity.CENTER);


    imgLayout.setOrientation(LinearLayout.VERTICAL);


    imgLayout.setPadding(imgPad,imgPad,imgPad,imgPad);


    imgLayout.setBackgroundColor(LL.getVariables().getInteger(“main_color”));



    //=====================


    //======= Views =======


    //=====================


    //LL.runScript(“imageActivityResult”,0);


    //Android.makeNewToast(lol,true).show();



    var avatarView= new ImageView(context);


    var img= acAvatar.getImage();


    var imgSize= d_width/4;


    var imgParams= new ViewGroup.LayoutParams(imgSize,imgSize);


    avatarView.setLayoutParams(imgParams);


    avatarView.setImageBitmap(img.getBitmap());



    avatarView.setOnClickListener({


    onClick: function(v){


    //avatarView.setScaleType(ImageView.ScaleType.CENTER_CROP);



    var color= LL.pickColor(“Choose the accent color”,0xffffffff,false);


    var intent= new Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI);


    var lol= context.startActivityForResult(Intent.createChooser(intent,”Choose an image picker”),script);



    //Android.makeNewToast(“sei fregato”,true).show();


    //avatarView.setImageBitmap(newImg.getBitmap());


    }


    });


    imgLayout.addView(avatarView);



    var tapOn= new TextView(context);


    tapOn.setText(“Tap the image to change it”);


    tapOn.setGravity(Gravity.CENTER);


    tapOn.setPadding(0,textPad,0,0);


    tapOn.setTextColor(LL.getVariables().getInteger(“text_color”));


    imgLayout.addView(tapOn);




    var txtName= new TextView(context);


    txtName.setText(“Name”);


    txtName.setPadding(0,textPad,0,0);


    layout.addView(txtName);



    var name= new EditText(context);


    name.setText(acName.getLabel(),TextView.BufferType.EDITABLE);


    name.setInputType(InputType.TYPE_CLASS_TEXT);


    name.setTextColor(textColor);


    layout.addView(name);



    var txtMail= new TextView(context);


    txtMail.setText(“E-mail or description”);


    //txtMail.setPadding(0,imgPad,0,0);


    layout.addView(txtMail);



    var mail= new EditText(context);


    mail.setText(acMail.getLabel(),TextView.BufferType.EDITABLE);


    mail.setInputType(InputType.TYPE_CLASS_TEXT);


    mail.setTextColor(textColor);


    layout.addView(mail);



    mainLayout.addView(imgLayout);


    mainLayout.addView(layout);





    //======================


    //======= Dialog =======


    //======================



    var builder= new AlertDialog.Builder(context,style);


    builder.setView(mainLayout);



    builder.setPositiveButton(“Save”,new DialogInterface.OnClickListener(){


    onClick:function(dialog,id){


    acName.setLabel(name.getText(),true);


    acMail.setLabel(mail.getText(),true);


    dialog.dismiss();


    }


    });



    builder.setOnDismissListener({


    onDismiss: function(dialog){


    Android.makeNewToast(“come?”,true).show();


    }


    });



    builder.setNegativeButton(“Cancel”,new DialogInterface.OnClickListener(){


    onClick:function(dialog,id){


    dialog.cancel();


    }


    });



    builder.create().show();



    ——————————————


    The receiver script contains only an alert…

    ]]>

  8. Anonymous says:

    < ![CDATA[

    I am late to see this, sorry, but the startActivityForResult call is wrong. You shouldn’t call it on a context instance because you cannot handle the result yourself here (you cannot override the onActivityResult method, which by the way cannot be used in the main app activity because of the launch mode). The newly created icon (and the crash after) is because the launcher receives an unexpected activity result and wrongly think there is something to do.


    Try this instead: LL.startActivityForResult(intent, script, null)

    ]]>

  9. Anonymous says:

    < ![CDATA[

    Pierre Hébert so, as you said in a old post: “any other picking context will be ignored” now I understand what you said. Anyway, I tried to use null as third parameter and it works, now I only have to find another way…


    Thanks to all for your help!! 🙂

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *