@@ -55,9 +55,9 @@ public class MainActivity extends AppCompatActivity {
5555 private SubsamplingScaleImageView imageView ;
5656 private TextView logTextView ;
5757 private boolean initProcess ;
58- private final String galleryPath = Environment . getExternalStorageDirectory ()
59- + File . separator + Environment .DIRECTORY_DCIM
60- + File .separator + "RealSR" + File .separator ;
58+ private final String galleryPath =
59+ Environment . getExternalStoragePublicDirectory ( Environment .DIRECTORY_DCIM )
60+ + File .separator + "RealSR" + File .separator ;
6161 private File outputFile ;
6262 private String dir ;
6363 // dir="/data/data/com.tumuyan.ncnn.realsr/cache/realsr";
@@ -185,19 +185,49 @@ public void shareImage(String path) {
185185 Intent share_intent = new Intent ();
186186 ArrayList <Uri > imageUris = new ArrayList <Uri >();
187187
188- File file = new File (dir , path );
189- if (file .exists ()) {
188+ Uri contentUri = null ;
189+ File file = null ;
190+ if (!outputSavePath .isEmpty ()) {
191+ file = new File (outputSavePath );
192+ if (file .exists ()) {
193+ contentUri = FileProvider .getUriForFile (this ,
194+ BuildConfig .APPLICATION_ID + ".fileprovider" ,
195+ file );
196+ }
197+ }
198+
199+ if (contentUri == null ) {
200+ file = new File (dir , path );
201+ if (file .exists ()) {
202+ contentUri = FileProvider .getUriForFile (this ,
203+ BuildConfig .APPLICATION_ID + ".fileprovider" ,
204+ file );
205+ }
206+ }
207+
208+ if (contentUri != null ) {
190209
191- Uri contentUri = FileProvider .getUriForFile (this ,
192- BuildConfig .APPLICATION_ID + ".fileprovider" ,
193- file );
194210 imageUris .add (contentUri );
211+ String suffix = file .getName ().replaceFirst (".+\\ .([^.]+)$" , "$1" ).toLowerCase (Locale .ROOT );
212+ if (suffix .equals ("png" ))
213+ share_intent .setType ("image/png" );
214+ else if (suffix .equals ("jpg" ))
215+ share_intent .setType ("image/jpg" );
216+ else if (suffix .equals ("webp" ))
217+ share_intent .setType ("image/webp" );
218+ else if (suffix .equals ("heif" ))
219+ share_intent .setType ("image/heif" );
220+ else if (suffix .equals ("gif" ))
221+ share_intent .setType ("image/gif" );
222+ else
223+ share_intent .setType ("image/*" );
195224
196- share_intent .setAction (Intent .ACTION_SEND_MULTIPLE );//设置分享行为
197- share_intent .setType ("image/png" );//设置分享内容的类型
225+ share_intent .setAction (Intent .ACTION_SEND );//设置分享行为
198226 share_intent .addFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION | Intent .FLAG_GRANT_WRITE_URI_PERMISSION );
199- share_intent .putParcelableArrayListExtra (Intent .EXTRA_STREAM , imageUris );
227+ share_intent .putExtra (Intent .EXTRA_STREAM , contentUri );
228+ Log .i ("shareImage()" , "uri = " + contentUri .toString ());
200229 startActivity (Intent .createChooser (share_intent , "Share" ));
230+
201231 } else {
202232 Toast .makeText (getApplicationContext (), R .string .output_not_exits , Toast .LENGTH_SHORT ).show ();
203233 }
@@ -661,19 +691,23 @@ public boolean run_command(@NonNull String command) {
661691 Log .d ("run_command" , "command=" + command + "; break" );
662692 return false ;
663693 }
694+ String cmd [];
695+ if (command .startsWith ("./magick" )) {
696+ cmd = new String []{"/bin/sh" , "-c" , "cd " + dir + "; export LD_LIBRARY_PATH=" + dir + " ; " + command };
697+ } else cmd = new String []{"/bin/sh" , "-c" , command };
664698
665699 StringBuilder con = new StringBuilder ();
666700 String result ;
667701
668702 try {
669- Process process = Runtime .getRuntime ().exec (command );
703+ Process process = Runtime .getRuntime ().exec (cmd );
670704 BufferedReader br = new BufferedReader (new InputStreamReader (process .getInputStream ()));
671705 while ((result = br .readLine ()) != null ) {
672706 con .append (result );
673707 con .append ('\n' );
674708 }
675709
676- } catch (IOException e ) {
710+ } catch (Exception e ) {
677711 // TODO Auto-generated catch block
678712 e .printStackTrace ();
679713
@@ -748,7 +782,7 @@ public synchronized boolean run20(@NonNull String cmd) {
748782 os .writeBytes ("cd " + dir + "\n " );
749783 os .flush ();
750784
751- if (cmd .startsWith ("./magick" )) {
785+ if (cmd .startsWith ("./magick" ) || save ) {
752786 os .writeBytes ("export LD_LIBRARY_PATH=" + dir + "\n " );
753787 os .flush ();
754788 }
@@ -845,7 +879,7 @@ public synchronized boolean run20(@NonNull String cmd) {
845879 if (process .exitValue () != 0 )
846880 process .destroy ();
847881 } catch (Exception e ) {
848- e .printStackTrace ();
882+ // e.printStackTrace();
849883 }
850884
851885 if (newTask || process == null ) {
0 commit comments