Android Question Read sd card information

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Hi, I got error: java.io.FileNotFoundException: /sys/block/mmcblk0/device/serial (Permission denied)
Any suggestion?

manifest:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.

AddPermission(android.permission.READ_EXTERNAL_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)
AddPermission(android.permission.MANAGE_EXTERNAL_STORAGE)

SetApplicationAttribute(android:requestLegacyExternalStorage, true)

main activity:
#Region  Project Attributes
    #ApplicationLabel: sdcard id
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region
    #BridgeLogger: True
    
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Dim rp As RuntimePermissions
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
   
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
        
End Sub


Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result=True Then
        Dim jo As JavaObject
        Log(jo.InitializeContext.RunMethod("getExternalSdCARDId",Null))   
    End If
End Sub



#IF JAVA

import java.io.*;

public String getExternalSdCARDId() {

        String path2 = "/sys/block/mmcblk0/device";
        
try{
        BufferedReader serial;
        BufferedReader name ;
        BufferedReader manfid;
        BufferedReader oemid;
        BufferedReader mfDate;
        BufferedReader CID;

        serial = new BufferedReader(new FileReader(path2 + "/serial"));
        name = new BufferedReader(new FileReader(path2 + "/name"));
        manfid = new BufferedReader(new FileReader(path2 + "/manfid"));
        oemid = new BufferedReader(new FileReader(path2 + "/oemid"));
        mfDate = new BufferedReader(new FileReader(path2 + "/date"));
        CID = new BufferedReader(new FileReader(path2 + "/cid"));

        String sdSerial = serial.readLine();
        String sdName = name.readLine();
        String sdMfId = manfid.readLine();
        String sdOemId = oemid.readLine();
        String sdMfDate = mfDate.readLine();
        String sdCid = CID.readLine();
        
        return sdSerial;
} catch(Exception e) {
    return "error: " + e;
}       
}

#End If
 
Top