1919import java .util .Collections ;
2020import java .util .LinkedList ;
2121import java .util .Locale ;
22- import com .foxdebug .acode .R ;
2322
2423public class AlpineDocumentProvider extends DocumentsProvider {
2524
@@ -60,7 +59,7 @@ public Cursor queryRoots(String[] projection) {
6059 MatrixCursor result = new MatrixCursor (
6160 projection != null ? projection : DEFAULT_ROOT_PROJECTION
6261 );
63- String applicationName = "Acode" ;
62+ String applicationName = getApplicationLabel () ;
6463
6564 MatrixCursor .RowBuilder row = result .newRow ();
6665 row .add (DocumentsContract .Root .COLUMN_ROOT_ID , getDocIdForFile (BASE_DIR ));
@@ -75,7 +74,7 @@ public Cursor queryRoots(String[] projection) {
7574 row .add (DocumentsContract .Root .COLUMN_TITLE , applicationName );
7675 row .add (DocumentsContract .Root .COLUMN_MIME_TYPES , ALL_MIME_TYPES );
7776 row .add (DocumentsContract .Root .COLUMN_AVAILABLE_BYTES , BASE_DIR .getFreeSpace ());
78- row .add (DocumentsContract .Root .COLUMN_ICON , R . mipmap . ic_launcher );
77+ row .add (DocumentsContract .Root .COLUMN_ICON , resolveLauncherIcon () );
7978 return result ;
8079 }
8180
@@ -364,4 +363,22 @@ private static String getMimeType(File file) {
364363 return "application/octet-stream" ;
365364 }
366365 }
366+ private int resolveLauncherIcon () {
367+ Context context = getContext ();
368+ if (context == null ) return android .R .mipmap .sym_def_app_icon ;
369+ int icon = context .getResources ().getIdentifier ("ic_launcher" , "mipmap" , context .getPackageName ());
370+ return icon != 0 ? icon : android .R .mipmap .sym_def_app_icon ;
371+ }
372+
373+ private String getApplicationLabel () {
374+ Context context = getContext ();
375+ if (context == null ) return "Acode" ;
376+ PackageManager pm = context .getPackageManager ();
377+ try {
378+ CharSequence label = pm .getApplicationLabel (context .getApplicationInfo ());
379+ return label != null ? label .toString () : "Acode" ;
380+ } catch (Exception ignored ) {
381+ return "Acode" ;
382+ }
383+ }
367384}
0 commit comments