Guest User

Untitled

a guest
Mar 28th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. package com.example.audioplayer;
  2.  
  3. import android.content.ContentProvider;
  4. import android.content.ContentValues;
  5. import android.content.Context;
  6. import android.database.Cursor;
  7. import android.database.sqlite.SQLiteDatabase;
  8. import android.database.sqlite.SQLiteOpenHelper;
  9. import android.net.Uri;
  10.  
  11. public class musicdb extends ContentProvider {
  12.  
  13. private static final int DB_VERSION = 1;
  14. private static final String DB_NAME = "mydb";
  15. static final String DB_TABLE_NAME = "musiclist";
  16. static final String DB_SONG_NAME = "songname";
  17. static final String DB_SDPATH = "localpath";
  18. static final String DB_IPATH = "ipath";
  19. private static final String DB_TABLE_CREATE = "CREATE TABLE " + DB_TABLE_NAME
  20. + "(_id INTEGER PRIMARY KEY AUTOINCREMENT ,"
  21. + DB_SONG_NAME + " TEXT NOT NULL,"
  22. + DB_SDPATH + " TEXT,"
  23. + DB_IPATH + " TEXT);";
  24.  
  25.  
  26. databasehelper dbHelper;
  27. SQLiteDatabase database;
  28.  
  29. @Override
  30. public int delete(Uri uri, String selection, String[] selectionArgs) {
  31. // Implement this to handle requests to delete one or more rows.
  32. throw new UnsupportedOperationException("Not yet implemented");
  33. }
  34.  
  35. @Override
  36. public String getType(Uri uri) {
  37. // TODO: Implement this to handle requests for the MIME type of the data
  38. // at the given URI.
  39. throw new UnsupportedOperationException("Not yet implemented");
  40. }
  41.  
  42. @Override
  43. public Uri insert(Uri uri, ContentValues values) {
  44. database = dbHelper.getWritableDatabase();
  45. database.insert(DB_TABLE_NAME, null, values);
  46.  
  47. return uri;
  48. }
  49.  
  50. @Override
  51. public boolean onCreate() {
  52. dbHelper = new databasehelper(getContext());
  53. return dbHelper == null ? true : false;
  54. }
  55.  
  56. @Override
  57. public Cursor query(Uri uri, String[] projection, String selection,
  58. String[] selectionArgs, String sortOrder) {
  59.  
  60. database = dbHelper.getWritableDatabase();
  61. Cursor cursor = database.query(DB_TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder);
  62.  
  63. return cursor;
  64. }
  65.  
  66. @Override
  67. public int update(Uri uri, ContentValues values, String selection,
  68. String[] selectionArgs) {
  69. // TODO: Implement this to handle requests to update one or more rows.
  70. throw new UnsupportedOperationException("Not yet implemented");
  71. }
  72.  
  73. class databasehelper extends SQLiteOpenHelper {
  74.  
  75. public databasehelper(Context context) {
  76. super(context, DB_NAME, null, DB_VERSION);
  77. }
  78.  
  79. @Override
  80. public void onCreate(SQLiteDatabase db) {
  81. db.execSQL(DB_TABLE_CREATE);
  82.  
  83. }
  84.  
  85. @Override
  86. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  87.  
  88. }
  89. }
  90. }
Add Comment
Please, Sign In to add comment