我的代码出了什么问题?当我发表评论时,它的效果非常好。
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();
}
}
当我想在我的设备中运行此代码时,它说:
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]
我搜索了很多,但没有找到任何解决方案,请帮忙
答案 0 :(得分:0)
我找到了一个解决方案,但我完全震惊为什么它现在正在工作?!!!!! 我从intent范围中删除了try catch。 原始代码:
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());
}
固定代码:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(dest));
startActivity(intent);
现在工作得很好。