Guest User

Untitled

a guest
Sep 14th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. How to load .3gp file link stored in sdcard to database
  2. public class DatabaseUtil {
  3. private static final String DB_NAME="call_recordings";
  4. private static final int DB_VERSION=1;
  5. SQLiteDatabase db;
  6.  
  7. public DatabaseUtil(Context context) {
  8. MyHelper helper = new MyHelper(context);
  9. db = helper.getWritableDatabase();
  10. }
  11.  
  12.  
  13. public class MyHelper extends SQLiteOpenHelper
  14. {
  15. String root="/sdcard/AudioRecorder1";
  16. File directory = Environment.getExternalStorageDirectory();
  17. File f = new File(directory + root);
  18. File[] files = f.listFiles();
  19. String[] str1;
  20. String str2[];
  21.  
  22. public void filepath(String s)
  23. {
  24.  
  25. for(int i=0; i < files.length; i++)
  26. {
  27. File file = files[i];
  28. str1[i]=file.getPath();
  29. str2[i]=file.getName();
  30. System.out.println("file is"+str1[i]);
  31. addrecords(str2[i]);
  32. }
  33.  
  34. }
  35.  
  36. // File file[] = directory.listFiles();
  37. // System.out.println("The length of files is " + file.length);
  38.  
  39.  
  40.  
  41. // for(int i=0;i<file.length;i++)
  42.  
  43. //for each file object get any details you wish to using the standard functions...jst google :)
  44.  
  45.  
  46.  
  47. public MyHelper(Context context) {
  48. super(context, DB_NAME, null, DB_VERSION);
  49. }
  50. @Override
  51. public void onCreate(SQLiteDatabase db) {
  52. db.execSQL("create table recordings(path varchar)");
  53. }
  54. @Override
  55. public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
  56.  
  57. }
  58. }
  59. public void addrecords(String sName)
  60. {
  61. SQLiteStatement stmt = db.compileStatement("insert into recordings values(?)");
  62. stmt.bindString(1, sName);
  63. //stmt.bindString(2, sQua);
  64. stmt.executeInsert();
  65. }
  66.  
  67. public String getrecords()
  68. {``
  69. Cursor c = db.query("recordings", new String[]{"path"}, null, null, null, null, null);
  70. StringBuffer sb = new StringBuffer();
  71. if(c.moveToFirst())
  72. {
  73. do
  74. {
  75. sb.append(c.getString(0) + " : ");
  76. sb.append(c.getString(1) + "n");
  77. }while(c.moveToNext());
  78. }
  79. return sb.toString();
  80. }
  81. }
Add Comment
Please, Sign In to add comment