|
|
@ -28,7 +28,7 @@ import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class four extends AppCompatActivity {
|
|
|
|
public class four extends AppCompatActivity {
|
|
|
@ -39,6 +39,7 @@ public class four extends AppCompatActivity {
|
|
|
|
ImageView iv_photo;
|
|
|
|
ImageView iv_photo;
|
|
|
|
Uri imageUri;
|
|
|
|
Uri imageUri;
|
|
|
|
TextView t1;
|
|
|
|
TextView t1;
|
|
|
|
|
|
|
|
String a="111";
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState){
|
|
|
|
protected void onCreate(Bundle savedInstanceState){
|
|
|
|
|
|
|
|
|
|
|
@ -94,11 +95,21 @@ public class four extends AppCompatActivity {
|
|
|
|
Toast.makeText(this, "请至权限中心打开应用权限", Toast.LENGTH_SHORT).show();
|
|
|
|
Toast.makeText(this, "请至权限中心打开应用权限", Toast.LENGTH_SHORT).show();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 新建目录appDir,并把图片存到其下
|
|
|
|
// 新建目录appDir,并把图片存到其下
|
|
|
|
File appDir = new File(context.getExternalFilesDir(null).getPath()+ "BarcodeBitmap");
|
|
|
|
File appDir = new File(context.getExternalFilesDir(null).getPath() + "BarcodeBitmap");
|
|
|
|
if (!appDir.exists()) {
|
|
|
|
if (!appDir.exists()) {
|
|
|
|
appDir.mkdir();
|
|
|
|
appDir.mkdir();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String fileName = "p2" + ".jpg";
|
|
|
|
|
|
|
|
|
|
|
|
Random random = new Random();
|
|
|
|
|
|
|
|
//生成随机数的个数
|
|
|
|
|
|
|
|
int random1 = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
|
|
|
|
random1 = random.nextInt(1000000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String fileName = String.format("%s.jpg", String.valueOf(random1));
|
|
|
|
|
|
|
|
a = context.getExternalFilesDir(null).getPath() + "BarcodeBitmap/" + fileName;
|
|
|
|
|
|
|
|
|
|
|
|
File file = new File(appDir, fileName);
|
|
|
|
File file = new File(appDir, fileName);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
|
@ -111,18 +122,18 @@ public class four extends AppCompatActivity {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 把file里面的图片插入到系统相册中
|
|
|
|
// // 把file里面的图片插入到系统相册中
|
|
|
|
try {
|
|
|
|
// try {
|
|
|
|
MediaStore.Images.Media.insertImage(context.getContentResolver(),
|
|
|
|
// MediaStore.Images.Media.insertImage(context.getContentResolver(),
|
|
|
|
file.getAbsolutePath(), fileName, null);
|
|
|
|
// file.getAbsolutePath(), fileName, null);
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
// } catch (FileNotFoundException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
// e.printStackTrace();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
Toast.makeText(this, fileName, Toast.LENGTH_LONG);
|
|
|
|
// Toast.makeText(this, fileName, Toast.LENGTH_LONG);
|
|
|
|
|
|
|
|
//
|
|
|
|
// 通知相册更新
|
|
|
|
// // 通知相册更新
|
|
|
|
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
|
|
|
|
// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -137,9 +148,16 @@ public class four extends AppCompatActivity {
|
|
|
|
//将图片保存
|
|
|
|
//将图片保存
|
|
|
|
bitmap= BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
|
|
|
|
bitmap= BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
|
|
|
|
iv_photo.setImageBitmap(bitmap);
|
|
|
|
iv_photo.setImageBitmap(bitmap);
|
|
|
|
Ingredient qw=new Ingredient();
|
|
|
|
|
|
|
|
t1.setText("###"+qw.ingredient());
|
|
|
|
|
|
|
|
saveImageToGallery(four.this,bitmap);
|
|
|
|
saveImageToGallery(four.this,bitmap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ingredient qw=new Ingredient(a);
|
|
|
|
|
|
|
|
//t1.setText("###"+qw.ingredient());
|
|
|
|
|
|
|
|
//ToIngredient qw=new ToIngredient(a);
|
|
|
|
|
|
|
|
String str=qw.ingredient();
|
|
|
|
|
|
|
|
// String name=str.substring(str.indexOf("name")+7,str.indexOf("\"}"));
|
|
|
|
|
|
|
|
// String odds=str.substring(str.indexOf("score")+7,str.indexOf(","));
|
|
|
|
|
|
|
|
// String k="有"+odds.substring(0,4)+"的概率是"+name;
|
|
|
|
|
|
|
|
t1.setText("图片保存位置:"+"\n"+a+"\n"+"识别结果:"+"\n"+str);//qw.ingredient());
|
|
|
|
//public void saveMyBitmap(Bitmap mBitmap,String bitName){\n\n
|
|
|
|
//public void saveMyBitmap(Bitmap mBitmap,String bitName){\n\n
|
|
|
|
|
|
|
|
|
|
|
|
// File f = new File( "/sdcard/baidu/"+"jpg1" + ".jpg");
|
|
|
|
// File f = new File( "/sdcard/baidu/"+"jpg1" + ".jpg");
|
|
|
|