i want to create database in sdcard or external sdcard for this i have try this code and using this i have successfully created database in sdcard but in logcat it give me warning like below
Logcat
07-18 14:18:22.140: W/FileUtils(8595): Failed to chmod(/mnt/sdcard/peakmedia/DB_PMD): libcore.io.ErrnoException: chmod failed: EPERM (Operation not permitted)
DB_Helper.java
public class DB_Helper extends SQLiteOpenHelper
{
public DB_Helper(Context context)
{
super(context, Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + DB_Constant.DB.FILE_DIR
+ File.separator + DB_Constant.DB.DATABASENAME, null, DB_Constant.DB.DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
String query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYFILES_TABLE);
db.execSQL(query);
query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYUSERS_TABLE);
db.execSQL(query);
query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYPLAYLIST_TABLE);
db.execSQL(query);
query=String.format(DB_Constant.CREATE_TABLE_QUERY.CREATE_MYDEVICE_TABLE);
db.execSQL(query);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
if(newVersion > oldVersion)
{
db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYFILES);
onCreate(db);
db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYUSERS);
onCreate(db);
db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYPLAYLIST);
onCreate(db);
db.execSQL("DROP TABLE IF EXISTS "+ DB_Constant.TABLE.MYDEVICE);
onCreate(db);
}
}
}
Just solved this problem.
You have to let your app join linux build to grant it SYSTEM permission.
add this line into Android.mk
LOCAL_CERTIFICATE := platform
add this into manifest node of AndroidManifest.xml
android:sharedUserId="android.uid.system"
Generate apk and push it into /system/app/
Now you can try to run
final String command = "chmod 777 /data/ena";
Process p = Runtime.getRuntime().exec(command);
or
File file = new File("/data/ena");
if (file.exists()) {
boolean result = file.setExecutable(true);
Log.e(TAG, "trpb67, RESULT IS " + result);
}
value of result should be true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With