Guest User

Untitled

a guest
Jan 24th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. /**
  2.  
  3. com.kosso.contentquery
  4.  
  5. A Titanium Android module to try and get the actual path of a contenUri returned from a RECORD_SOUND_ACTION Intent Activity.
  6.  
  7. by Kosso. (so far! ;p )
  8.  
  9. **/
  10. package com.kosso.contentquery;
  11.  
  12. import org.appcelerator.kroll.KrollModule;
  13. import org.appcelerator.kroll.annotations.Kroll;
  14. import org.appcelerator.kroll.KrollInvocation;
  15.  
  16.  
  17. import org.appcelerator.titanium.TiContext;
  18.  
  19. import org.appcelerator.titanium.TiActivity;
  20. import org.appcelerator.titanium.util.TiActivityResultHandler;
  21. import org.appcelerator.titanium.util.TiActivitySupport;
  22. import org.appcelerator.titanium.util.TiActivitySupportHelper;
  23.  
  24. import org.appcelerator.titanium.util.Log;
  25. import org.appcelerator.titanium.util.TiConfig;
  26.  
  27. import android.net.Uri;
  28.  
  29.  
  30. import android.provider.MediaStore;
  31. //import android.provider.MediaStore.Audio.Media;
  32. import android.database.Cursor;
  33.  
  34. import android.app.Activity;
  35. import android.content.Context;
  36. import android.content.Intent;
  37.  
  38. import android.content.ContentResolver;
  39.  
  40.  
  41.  
  42. @Kroll.module(name="Contentquery", id="com.kosso.contentquery")
  43. public class ContentqueryModule extends KrollModule
  44. {
  45.  
  46. // Standard Debugging variables
  47. private static final String LCAT = "ContentqueryModule";
  48. private static final boolean DBG = TiConfig.LOGD;
  49.  
  50.  
  51. public ContentqueryModule(TiContext tiContext) {
  52. super(tiContext);
  53. }
  54.  
  55.  
  56. // Ok here's where I'm trying to do the query...
  57.  
  58. @Kroll.method
  59. public String getDataPath(String contentUri) {
  60.  
  61.  
  62. Uri theContentUri = Uri.parse(contentUri);
  63.  
  64.  
  65. // All I want is the _data for now..
  66. /*
  67. String[] projection = {
  68. "_data"
  69. };
  70. */
  71. String[] projection = { MediaStore.Audio.Media.DATA };
  72.  
  73. String dataPath = "";
  74.  
  75. // Do the query .. (I think this is how its done)
  76. Cursor mCur = getTiContext().getActivity().getContentResolver().query(theContentUri, projection, null, null, null);
  77.  
  78. Log.d(ContentqueryModule.class.getName(), new StringBuilder().append("####### ### CALLING getDataPath ").toString());
  79.  
  80. mCur.moveToFirst();
  81.  
  82. while (mCur.isAfterLast() == false) {
  83. for (int i=0; i<mCur.getColumnCount(); i++) {
  84.  
  85. // this probably isn't the right way to do this either... but it'll do for now... sigh...
  86. dataPath = mCur.getString(i);
  87.  
  88. Log.d(ContentqueryModule.class.getName(), new StringBuilder().append("############# getDataPath: ").append(mCur.getString(i)).toString());
  89.  
  90. }
  91. mCur.moveToNext();
  92. }
  93.  
  94. return dataPath;
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. // ignore these samples
  103.  
  104. // Methods
  105. @Kroll.method
  106. public String example() {
  107. Log.d(LCAT, "example called");
  108. return "hello world";
  109. }
  110.  
  111. // Properties
  112. @Kroll.getProperty
  113. public String getExampleProp() {
  114. Log.d(LCAT, "get example property");
  115. return "hello world";
  116. }
  117. @Kroll.setProperty
  118. public void setExampleProp(String value) {
  119. Log.d(LCAT, "set example property: " + value);
  120. }
  121.  
  122. }
Add Comment
Please, Sign In to add comment