Skip to content

Instantly share code, notes, and snippets.

@kosso
Created August 17, 2011 19:14
Show Gist options
  • Save kosso/1152360 to your computer and use it in GitHub Desktop.
Save kosso/1152360 to your computer and use it in GitHub Desktop.
An attempt at building a Titanium Android module to assist media intents ..
/**
com.kosso.contentquery
A Titanium Android module to try and get the actual path of a contenUri returned from a RECORD_SOUND_ACTION Intent Activity.
by Kosso. (so far! ;p )
**/
package com.kosso.contentquery;
import org.appcelerator.kroll.KrollModule;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.kroll.KrollInvocation;
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.TiActivity;
import org.appcelerator.titanium.util.TiActivityResultHandler;
import org.appcelerator.titanium.util.TiActivitySupport;
import org.appcelerator.titanium.util.TiActivitySupportHelper;
import org.appcelerator.titanium.util.Log;
import org.appcelerator.titanium.util.TiConfig;
import android.net.Uri;
import android.provider.MediaStore;
//import android.provider.MediaStore.Audio.Media;
import android.database.Cursor;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.ContentResolver;
@Kroll.module(name="Contentquery", id="com.kosso.contentquery")
public class ContentqueryModule extends KrollModule
{
// Standard Debugging variables
private static final String LCAT = "ContentqueryModule";
private static final boolean DBG = TiConfig.LOGD;
public ContentqueryModule(TiContext tiContext) {
super(tiContext);
}
// Ok here's where I'm trying to do the query...
@Kroll.method
public String getDataPath(String contentUri) {
Uri theContentUri = Uri.parse(contentUri);
// All I want is the _data for now..
/*
String[] projection = {
"_data"
};
*/
String[] projection = { MediaStore.Audio.Media.DATA };
String dataPath = "";
// Do the query .. (I think this is how its done)
Cursor mCur = getTiContext().getActivity().getContentResolver().query(theContentUri, projection, null, null, null);
Log.d(ContentqueryModule.class.getName(), new StringBuilder().append("####### ### CALLING getDataPath ").toString());
mCur.moveToFirst();
while (mCur.isAfterLast() == false) {
for (int i=0; i<mCur.getColumnCount(); i++) {
// this probably isn't the right way to do this either... but it'll do for now... sigh...
dataPath = mCur.getString(i);
Log.d(ContentqueryModule.class.getName(), new StringBuilder().append("############# getDataPath: ").append(mCur.getString(i)).toString());
}
mCur.moveToNext();
}
return dataPath;
}
// ignore these samples
// Methods
@Kroll.method
public String example() {
Log.d(LCAT, "example called");
return "hello world";
}
// Properties
@Kroll.getProperty
public String getExampleProp() {
Log.d(LCAT, "get example property");
return "hello world";
}
@Kroll.setProperty
public void setExampleProp(String value) {
Log.d(LCAT, "set example property: " + value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment