3838import android .net .Uri ;
3939import android .os .AsyncTask ;
4040import android .os .Environment ;
41+ import android .os .Process ;
4142import android .os .ServiceManager ;
4243import android .provider .MediaStore ;
4344import android .util .DisplayMetrics ;
5455import android .widget .FrameLayout ;
5556import android .widget .ImageView ;
5657
57- import com .android .server .wm .WindowManagerService ;
5858import com .android .systemui .R ;
5959
6060import java .io .File ;
6868class SaveImageInBackgroundData {
6969 Context context ;
7070 Bitmap image ;
71+ Uri imageUri ;
7172 Runnable finisher ;
7273 int iconSize ;
7374 int result ;
@@ -128,9 +129,6 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
128129 (iconHeight - data .iconSize ) / 2 , data .iconSize , data .iconSize );
129130
130131 // Show the intermediate notification
131- mLaunchIntent = new Intent (Intent .ACTION_VIEW );
132- mLaunchIntent .setDataAndType (Uri .fromFile (new File (mImageFilePath )), "image/png" );
133- mLaunchIntent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
134132 mTickerAddSpace = !mTickerAddSpace ;
135133 mNotificationId = nId ;
136134 mNotificationBuilder = new Notification .Builder (context )
@@ -152,6 +150,10 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
152150 protected SaveImageInBackgroundData doInBackground (SaveImageInBackgroundData ... params ) {
153151 if (params .length != 1 ) return null ;
154152
153+ // By default, AsyncTask sets the worker thread to have background thread priority, so bump
154+ // it back up so that we save a little quicker.
155+ Process .setThreadPriority (Process .THREAD_PRIORITY_FOREGROUND );
156+
155157 Context context = params [0 ].context ;
156158 Bitmap image = params [0 ].image ;
157159
@@ -178,6 +180,7 @@ protected SaveImageInBackgroundData doInBackground(SaveImageInBackgroundData...
178180 values .put (MediaStore .Images .ImageColumns .SIZE , new File (mImageFilePath ).length ());
179181 resolver .update (uri , values , null , null );
180182
183+ params [0 ].imageUri = uri ;
181184 params [0 ].result = 0 ;
182185 } catch (Exception e ) {
183186 // IOException/UnsupportedOperationException may be thrown if external storage is not
@@ -197,6 +200,11 @@ protected void onPostExecute(SaveImageInBackgroundData params) {
197200 // Show the final notification to indicate screenshot saved
198201 Resources r = params .context .getResources ();
199202
203+ // Create the intent to show the screenshot in gallery
204+ mLaunchIntent = new Intent (Intent .ACTION_VIEW );
205+ mLaunchIntent .setDataAndType (params .imageUri , "image/png" );
206+ mLaunchIntent .setFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
207+
200208 mNotificationBuilder
201209 .setContentTitle (r .getString (R .string .screenshot_saved_title ))
202210 .setContentText (r .getString (R .string .screenshot_saved_text ))
0 commit comments