2

what is wrong with my code? when I comment it,It works very well.

public void sendToOther(){

    PackageManager pm=getActivity().getPackageManager();
    try {
        PackageInfo info=pm.getPackageInfo(getActivity().getPackageName(), 0);
        ApplicationInfo ainfo = info.applicationInfo;

        File src = new File(ainfo.sourceDir);
        File dest = new File(getActivity().getExternalCacheDir(), "myfile.apk");
        if (src.exists()) {
            copyFile(src,dest);
            try{
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_SEND);
                intent.setType("image/jpeg");
                intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(dest));
                startActivity(intent);
            }catch (Exception e){
                Log.e("tag", e.toString());
            }
        }


    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }



}

when I want to run this code in my device, it says:

Waiting for device.
Target device: sony-st25i-192.168.1.102:5555
Uploading file
    local path: /mylocalpath/myapp.apk
    remote path: /data/local/tmp/com.myapp
Installing com.upkonid
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.myappp"
pkg: /data/local/tmp/com.myapp
Failure [INSTALL_FAILED_DEXOPT]

I searched a lot and I didn't find any solution, please help

sinoohe
  • 40,334
  • 3
  • 19
  • 16
  • why are you 'sending' a streamed .apk with a mime/type of 'jpeg' ??? also , u may want to google the 'uri.fromFile' ... because there may be a tweek needed for that when its a local file on EXT storage mount?? – Robert Rowntree Jun 29 '14 at 12:37
  • There is no DEX file in `/data/dalvik-cache` because dexopt failed while trying to create it. `does not include classes.dex` means your APK file doesn't have a "classes.dex" entry in it -- check it yourself with a Zip utility – CodeWalker Jun 29 '14 at 16:59
  • @RobertRowntree I wanted to send apk files from bluetooth, older android devices doesn't recognize to send apk files from bluetooth. – sinoohe Jun 30 '14 at 11:00
  • Mine happen with Facebook SDK. – neobie Dec 20 '14 at 15:23

1 Answers1

0

I found a solution, But I am completely shocked why it's working now?!!!!! I removed try catch from the intent scope. orginal code:

try{
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_SEND);
                intent.setType("image/jpeg");
                intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(dest));
                startActivity(intent);
            }catch (Exception e){
                Log.e("tag", e.toString());
            }

fixed code:

  Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_SEND);
                    intent.setType("image/jpeg");
                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(dest));
                    startActivity(intent);

It's working perfectly now.

sinoohe
  • 40,334
  • 3
  • 19
  • 16
  • I think it something else. Not worked for me... damn – djdance Jul 02 '14 at 18:00
  • debug your program from deleting codes and find out which file causes this error? I found this line(try catch) from this way – sinoohe Jul 03 '14 at 18:40
  • 1
    unfortunately, this appears if I add some SDK (facebook for example), and I cant check it for "hidden errors". But I solved it by uncheckin some option of IDE http://stackoverflow.com/a/18650805/2233069 – djdance Jul 04 '14 at 04:46