[Q] Help with Gallery App - Java for Android App Development

I have found a Gallery App on GitHub (https://github.com/sevenler/Android_Gallery2D_Custom) that I have integrated into my own app.
Currently the gallery displays all images from my device. What I would like to have is that it ONLY display the images starting at the folder on my sdcard that I specify such as..
private static String targetPath = Environment.getExternalStorageDirectory().toString() + "/DCIM/_private/.nomedia";
I tried several different modifications but I am really struggling.
I was hoping someone could take a look at the source code for the Gallery App on GitHub and tell me how to change it so it does not scan my entire device.
Thanks in advance!!
-Steve

StEVO_M said:
I have found a Gallery App on GitHub (https://github.com/sevenler/Android_Gallery2D_Custom) that I have integrated into my own app.
Currently the gallery displays all images from my device. What I would like to have is that it ONLY display the images starting at the folder on my sdcard that I specify such as..
private static String targetPath = Environment.getExternalStorageDirectory().toString() + "/DCIM/_private/.nomedia";
I tried several different modifications but I am really struggling.
I was hoping someone could take a look at the source code for the Gallery App on GitHub and tell me how to change it so it does not scan my entire device.
Thanks in advance!!
-Steve
Click to expand...
Click to collapse
I had a look at the source and from my understanding the important class here is that DataManager class here. Especially the getTopSetPath() with the static final Strings and maybe the mapMediaItems() methods seem to be where you need to look at. You might have to play around a bit, but this is where I would start.

SimplicityApks said:
I had a look at the source and from my understanding the important class here is that DataManager class here. Especially the getTopSetPath() with the static final Strings and maybe the mapMediaItems() methods seem to be where you need to look at. You might have to play around a bit, but this is where I would start.
Click to expand...
Click to collapse
I have tried adding/changing the following
Added...
//Setting Folder Path
public static final String targetPath = Environment.getExternalStorageDirectory().toString() + "/DCIM/_private/.nomedia";
Changed...
// This is the path for the media set seen by the user at top level.
private static final String TOP_SET_PATH = targetPath;
private static final String TOP_IMAGE_SET_PATH = "/combo/{/mtp,/local/image,/picasa/image}";
private static final String TOP_VIDEO_SET_PATH = "/combo/{/local/video,/picasa/video}";
private static final String TOP_LOCAL_SET_PATH = "/local/all";
private static final String TOP_LOCAL_IMAGE_SET_PATH = "/local/image";
private static final String TOP_LOCAL_VIDEO_SET_PATH = "/local/video";
I even tried setting all of the _PATH s to my targetPath
And I get a NullPointerException
12-13 11:07:47.881: E/AndroidRuntime(23029): Caused by: java.lang.NullPointerException
12-13 11:07:47.881: E/AndroidRuntime(23029): at com.myprivgallery.common.Utils.checkNotNull(Utils.java:48)
Which leads me to this in Utils.java
line 46 // Throws NullPointerException if the input is null.
line 47 public static <T> T checkNotNull(T object) {
line 48 if (object == null) throw new NullPointerException();
line 49 return object;
line 50 }
So if I am reading correctly, it is saying the path is empty. But I know that path works in other apps and it is not empty.

StEVO_M said:
I have tried adding/changing the following
Added...
//Setting Folder Path
public static final String targetPath = Environment.getExternalStorageDirectory().toString() + "/DCIM/_private/.nomedia";
Changed...
// This is the path for the media set seen by the user at top level.
private static final String TOP_SET_PATH = targetPath;
private static final String TOP_IMAGE_SET_PATH = "/combo/{/mtp,/local/image,/picasa/image}";
private static final String TOP_VIDEO_SET_PATH = "/combo/{/local/video,/picasa/video}";
private static final String TOP_LOCAL_SET_PATH = "/local/all";
private static final String TOP_LOCAL_IMAGE_SET_PATH = "/local/image";
private static final String TOP_LOCAL_VIDEO_SET_PATH = "/local/video";
I even tried setting all of the _PATH s to my targetPath
And I get a NullPointerException
12-13 11:07:47.881: E/AndroidRuntime(23029): Caused by: java.lang.NullPointerException
12-13 11:07:47.881: E/AndroidRuntime(23029): at com.myprivgallery.common.Utils.checkNotNull(Utils.java:48)
Which leads me to this in Utils.java
line 46 // Throws NullPointerException if the input is null.
line 47 public static <T> T checkNotNull(T object) {
line 48 if (object == null) throw new NullPointerException();
line 49 return object;
line 50 }
So if I am reading correctly, it is saying the path is empty. But I know that path works in other apps and it is not empty.
Click to expand...
Click to collapse
I don't think you can call an Environment method when static class variables are Initialised make sure that your String is the correct path with Logs, I would probably make that an instance variable instead...

SimplicityApks said:
I don't think you can call an Environment method when static class variables are Initialised make sure that your String is the correct path with Logs, I would probably make that an instance variable instead...
Click to expand...
Click to collapse
It may kinda look like I know what I'm doing, but looks are deceiving.
I really have no clue what I am doing. I consider myself a hack. I can some what look at code and then make it do what I want, but to actually program something new... I will see if I can't figure that out. But I really do appreciate your help.

StEVO_M said:
It may kinda look like I know what I'm doing, but looks are deceiving.
I really have no clue what I am doing. I consider myself a hack. I can some what look at code and then make it do what I want, but to actually program something new... I will see if I can't figure that out. But I really do appreciate your help.
Click to expand...
Click to collapse
Well then you should probably get started on a simpler app you've built yourself rather than trying to understand this very complex Gallery app (which in my view is poorly commented and documented)...
I had a closer look at the source and it seems that we are on the right track because the _PATH s are used in the getTopSetPath method of the DataManager, and a search reveals that it is called by various activities and pickers. If you're using one of those in your app we should be right.
Now let's get back to the basics, when the app is launched, the default launcher activity is Gallery.java. During it's creation, either startDefaultPage, startGetContent or startViewAction is called, but all of them have the following call:
Code:
data.putString(AlbumSetPage.KEY_MEDIA_PATH, getDataManager().getTopSetPath(DataManager.INCLUDE_ALL)); // or some other variable
So this is the path where the images are loaded. Honestly, I have no idea what the
Code:
"/combo/{/mtp,/local/all,/picasa/all}"
is doing in the path variable, it has to do something with the Combo classes in the data folder, since the app is loading images from different dirs. You can now call your Environment call there and somehow pass back Strings instead of Paths, but it would be nicer if we could somehow figure out the these Paths are used here. An important class is the LocalPhotoSource.java. That is also where getImage from the DataManager is called. You could have a look at that class as well. Which path do you want the gallery to scan actually? The best solution would be to further experiment with the _PATH String, without calling Environment as well as debugging the whole app from the start, so you can get an idea of how everything is working.

SimplicityApks said:
Well then you should probably get started on a simpler app you've built yourself rather than trying to understand this very complex Gallery app (which in my view is poorly commented and documented)...
I had a closer look at the source and it seems that we are on the right track because the _PATH s are used in the getTopSetPath method of the DataManager, and a search reveals that it is called by various activities and pickers. If you're using one of those in your app we should be right.
Now let's get back to the basics, when the app is launched, the default launcher activity is Gallery.java. During it's creation, either startDefaultPage, startGetContent or startViewAction is called, but all of them have the following call:
Code:
data.putString(AlbumSetPage.KEY_MEDIA_PATH, getDataManager().getTopSetPath(DataManager.INCLUDE_ALL)); // or some other variable
So this is the path where the images are loaded. Honestly, I have no idea what the
Code:
"/combo/{/mtp,/local/all,/picasa/all}"
is doing in the path variable, it has to do something with the Combo classes in the data folder, since the app is loading images from different dirs. You can now call your Environment call there and somehow pass back Strings instead of Paths, but it would be nicer if we could somehow figure out the these Paths are used here. An important class is the LocalPhotoSource.java. That is also where getImage from the DataManager is called. You could have a look at that class as well. Which path do you want the gallery to scan actually? The best solution would be to further experiment with the _PATH String, without calling Environment as well as debugging the whole app from the start, so you can get an idea of how everything is working.
Click to expand...
Click to collapse
I tried Changing the following in LocalAlbumSet.java
public class LocalAlbumSet extends MediaSet {
public static final Path PATH_ALL = Path.fromString("/DCIM/_private/.nomedia/all");
public static final Path PATH_IMAGE = Path.fromString("/DCIM/_private/.nomedia/image");
public static final Path PATH_VIDEO = Path.fromString("/DCIM/_private/.nomedia/video");
and Changing all of the TOP_..._Path s to
// This is the path for the media set seen by the user at top level.
private static final String TOP_SET_PATH = "/local/all";
private static final String TOP_IMAGE_SET_PATH = "/local/image";
private static final String TOP_VIDEO_SET_PATH = "/local/video";
private static final String TOP_LOCAL_SET_PATH = "/local/all";
private static final String TOP_LOCAL_IMAGE_SET_PATH = "/local/image";
private static final String TOP_LOCAL_VIDEO_SET_PATH = "/local/video";
I now see Random Images from /DCIM/_private/.nomedia but not all of them, which is really confusing. But at least it's a start.

StEVO_M said:
I have found a Gallery App on GitHub (https://github.com/sevenler/Android_Gallery2D_Custom) that I have integrated into my own app.
Currently the gallery displays all images from my device. What I would like to have is that it ONLY display the images starting at the folder on my sdcard that I specify such as..
private static String targetPath = Environment.getExternalStorageDirectory().toString() + "/DCIM/_private/.nomedia";
I tried several different modifications but I am really struggling.
I was hoping someone could take a look at the source code for the Gallery App on GitHub and tell me how to change it so it does not scan my entire device.
Thanks in advance!!
-Steve
Click to expand...
Click to collapse
Android gallery will not scan any folder having a .nomedia file in it.

EatHeat said:
Android gallery will not scan any folder having a .nomedia file in it.
Click to expand...
Click to collapse
So I am guessing there is no way to Force your own instance to scan it????

StEVO_M said:
So I am guessing there is no way to Force your own instance to scan it????
Click to expand...
Click to collapse
Delete the .nomedia file.

Lol. Not an option if I want to hide my pic.
Sent from my HTCONE using Tapatalk

Not sure what you are trying to achieve, if you want to scan it then why would you want to hide it?
If you want to add an option to allow it to scan or not, you could backup the .nomedia to another directory and delete it for the time being.
Just an idea, can't say for sure. Didn't try it ever.

I have created an app to hide pictures. Currently I have a very basic gallery. I was trying integrate this gallery because it has a lot more option such as editing and adding filters and such.
Sent from my HTCONE using Tapatalk

StEVO_M said:
I have created an app to hide pictures. Currently I have a very basic gallery. I was trying integrate this gallery because it has a lot more option such as editing and adding filters and such.
Click to expand...
Click to collapse
Well why do you need to? Make your app fulfill only one purpose, so let it hide the pictures (I guess by moving a .nomedia file into the folder right?) and then just create a shortcut in your app to the gallery app so the user can still use their preferred one... Makes more sense to me and is way less work.

StEVO_M said:
I have created an app to hide pictures. Currently I have a very basic gallery. I was trying integrate this gallery because it has a lot more option such as editing and adding filters and such.
Sent from my HTCONE using Tapatalk
Click to expand...
Click to collapse
A far more simple and logical way would be to create a hidden folder on the SD card with a .nomedia file in it. Images/videos that are to be hidden can be moved to that location. This would keep it hidden from the gallery and can only be accessed through your private gallery.
For unhiding media, just move them back to their original folders.

Let me try to explain further... As I said, I have created an app already that does the Basic things.
My Application looks like a standard App, a "To Do List", but if you press and hold an Icon on the main screen it prompts you for a Password (These passwords are setup on first use).
Now... Depending on which password you enter, it will either take you to the hidden Gallery OR if you enter a different password it will take you to a Hidden To Do List. This is so anyone that may stumble upon your app, you can show them that it's has a hidden area of the app. This way they have no clue you really have a Hidden Gallery.
If you enter the Hidden Gallery password then it would of course, take you to the hidden gallery.
The Current Features are...
Import from Main Gallery
Pinch to Zoom
Swipe
Share
Restore back to Main Gallery
Delete
Quick Escape ------ "Quick Escape" can be activate 2 ways. If you shake the phone while in the Hidden Gallery, the image will change to an image of your choosing or the default one that is set during install. OR..... A less obvious "Quick Escape" ... While in the Hidden Gallery, press the volume up or down and the image will switch. Either way, once it is in that mode, you can not press back. the only way out it to press the home button. This is designed so if someone grabs the phone out of your hand they will only see they Quick Escape" image and pressing back will not take them back to the gallery.
My app also appears in the standard Share menu, so if you are in your Main Gallery and want to hide a picture, you can share it to my app and it will then hide the picture.
I want to add More features to my Gallery, such as Filters, Editing (crop, rotate...), Frames... All the same things that you can do in the Main Gallery. The only thing I really don't want or need is a Camera function. I can't see someone taking the time to open my app and then get to the Hidden Gallery and then taking a picture, just so they can hide an image. Most would just take the picture as they always would and then "Share" it to my app.
I hope this explains Why I want to use the other Gallery rather than reinventing the wheel that already has all of these features built in. If I can not get that to work, maybe I can just pull the Features out and use those.
Anyone who wants to actually See the app in action, PM me and I will send you a DropBox link to install. FYI, It requires 4.0 or higher.

Related

event handling in dynamically created control

Hi all,
I am using eVC++ 4.0, and i've dynamically created a CListView like this:
Code:
lv.Create(0,_T(""),WS_CHILD|WS_VISIBLE,r,this,5);
but I dont know how to handle the events of this control... any ideas??
Mohammad
To get events from a listview (win32) I normally subclass it. I use the subclassing routine to post a message back to the parent when the user is doing something like tapping on it, then the windows routine can check whats selected etc and act on it. Is subclassing possible in mfc ?( I don't use it).
Thank u
but can anybody post some code??
thnx
Ok, I am a bit lazy to look up code at the moment, but here's something:
Yes, subclassing is possible in MFC. You just derive your class from the basic class provided like this:
Code:
class MyListView : pubic CListView
Then you add message handlers in the normal matter.
EDIT: The following passage is incorrect:
But I think subclassing may not be necessary in you case. List box controls send WM_COMMAND messages with notifications of major events like selection change to the parent window. All you have to do is to create a WM_COMMAND handler in your parent class.
Sorry I was thinking of ListBox not list view when I wrote it.
To manually add message handlers you need to put macros like ON_MESAGE or ON_COMMAND in the DECLARE_MESSAGE_MAP section of the class cpp file. All the detaisl are available on MSDN.
Are you saying that a listview will send the same WM_COMMAND as a list box in mfc? Dose this also happen in win32 made listviews. I have always thought it was a bit too tedious to find out when the user taps an item in the listview.
After reading your post levenum I had a quick look and it says that a WM_NOTIFY gets sent to the parent with a LVN_ITEMCHANGED for example. I had not used the LVN_**** because when I looked at them there was none that seem to deal with selections. I would guess that LVN_ITEMACTIVATE or LVN_ODSTATECHANGED would be usefull for this but then a second tap would not be picked up still leaving me wanting subclassing in many situations to get the users tap.
Ok, I have read what u wrote guys and my problem is almost solved, I used the OnNotify() method to handle messages sent from child controls like this:
Code:
BOOL CTest2Dlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
// TODO: Add your specialized code here and/or call the base class
if(wParam ==5 ) //5 is control ID
{
NMHDR *ph =(NMHDR*)lParam;
if(ph->code==NM_CLICK)
MessageBox("Click");
else if(ph->code==HDN_ITEMCLICK)
MessageBox("Item Click");
else
{
CString str;
str.Format("%d",ph->code);
MessageBox(str);
}
}
return CDialog::OnNotify(wParam, lParam, pResult);
}
Now there still a very small prolem: what messages should I handle for 'Selected Item Changed' event ?? I know its easy but I couldnt find it
Regards
mohgdeisat: I am sorry, I made a mistake about WM_COMMAND.
OdeeanRDeathshead is right, I was thinking of a list box not list view.
To make up for this, here is some sample code from a win32 dialog app that uses list view control. I hope it will be of some help:
Code:
//this is from the dialog window function:
case WM_NOTIFY: //handle events:
nmhdr = (LPNMHDR)lParam;
switch (nmhdr->idFrom)
{
case IDC_LEDLIST: //list control ID.
return OnLEDListEvent(hwndDlg, (LPNMLISTVIEW)lParam);
break;
}
break;
BOOL OnLEDListEvent(HWND hwndDlg, LPNMLISTVIEW nmlv)
{
/////
// Handles list view control notification messages
switch (nmlv->hdr.code)
{
case LVN_ITEMCHANGED:
return OnLEDListItemChanged(hwndDlg, nmlv);
break;
}
return 0;
}
BOOL OnLEDListItemChanged(HWND hwndDlg, LPNMLISTVIEW nmlv)
{
if (ListView_GetSelectionMark(nmlv->hdr.hwndFrom) != nmlv->iItem) return 0;
/* do what you need here */
return 0;
}
Don't mind the fact that I used 3 different functions. This is part of a bigger program and I am trying to keep things well organized without resorting to classes.
As I understand it, LVN_ITEMCHANGE is received for different reasons so I try to handle only the one coming from selected item. LVN_ITEMACTIVATE is only sent when you double click the item so if you just want to catch selection change you need to use LVN_ITEMCHANGE.
Once again, sorry for confusing you before.
thanx pals, good job!!!
I think my problem is now solved with ur help :wink:
Mohammad
Ok guys, I said that my problem was solved, yet, another problem arises...
When the list view is in the report mode, how can I determine when a header button is clicked, and determine which one was clicked???????
thanx in advance
To identify a header column click, you need to handle the WM_NOTIFY/HDN_ITEMCLICK message. Normally this message will be received by the header's parent control (i.e. the listview) -- some frameworks may redirect the message to the header control itself. I haven't worked with MFC in 10 years so I can't really if it reflects notification messages back to the control.
If you're trying to implement column sort, do yourself a favor and check out the Windows Template Library (WTL) at sourceforge.net. It's a set of C++ template classes that provide a thin yet useful wrapper around the standard Windows UI components. One of the classes is a sortable listview control. I've been using WTL with big Windows for more than 5 years -- you couldn't pay me to go back to MFC.
hi,
I have seen the WTL library and it seems very useful and time-saver, but I have a couple of questions about it:
1. can WTL 8.0 be installed with VC++ 6.0, specifically the appwizard stuff??how?? I see only javascript files of vc7.0 and 7.1 and 8.0!!
2. is there a good documentation about those classes??
Mohammad
I don't know about WTL 8; I'm still using WTL 7.5 with VS .Net 2003 for all my Win32 development. My guess is that it wouldn't work too well, as WTL is based on ATL, which has substantially changed between VC 6 and 7.
Good references for WTL include www.codeproject.com/wtl, and the WTL group over at Yahoo groups (reflected at www.gmane.org).

[Q] app crashes whenever call is made to change the content viewthe

whenever I use
Code:
tv.setText("Game Over!"); setContentView(tv);
my program crashes (note: tv is an object of the TextView class)
Before this call is made the program is set to a default view that contains a text view, buttons, etc. But the crash only happens when I call the method to change the view. Any ideas?
You probably wouldnt wanna do setContentView on a textview, unless its the only thing you want on the screen. Are you creating the textview dynamically? (In the java code) Or is this a textview you create in the xml. If you are doing it dynamically, are you giving it LayoutParams first?
Yes its dynamic. What kind of LayoutParams do you mean?
Sent from my GT-I9000M using XDA App
If you just create a new textview...
TextView text = new TextView(context);
its just floating around not attached to anything. Just create a quick layout with a textview in it, and do
setContentView(R.layout.layout2);
or you could try
tv.setLayoutParams(new LayoutParams(LayoutParam.WRAP_CONTENT,LayoutParam.WRAP_CONTENT));
It still crashes, no matter what I do as soon as I try to do anything with the TextView tv, it crashes
setting it works: final TextView tv = (TextView) findViewById(R.id.stats);
But doing ANYTHING with tv crashes.
Examples:
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams. WRAP_CONTENT));
tv.setText("testing");
Anything I'm overlooking?
Well for starters you cant change anything about a variable that you declare as final..

Image Low Quality

Hey,
So I'm making an app that needs to display a bitmap or raw (something where X/Y pixels can be modified, so no compression like a jpg).
There's an Activity which contains only an ImageView, I get the Bitmap from the bundle given in the callback from the camera (it's put into the intent before the Activity starts), then I set it to the ImageView in onCreate of this new Activity (which is basically only an ImageView).
For some reason, when viewing this Activity, the picture is of EXTREMELY low quality. Like, tons of jaggies, like it's a thumbnail or something and is force-scaled up to the screen size. The image isn't really like this, though, when I view it in my gallery it's crystal clear. So why is the quality being dragged down to all hell when I set it in the ImageView? I don't care about the performance constraints, this isn't a production app.
I feel there's some quality control function in the ImageView or something, but I have no idea what. Can somebody tell me the "why" or the "fix" - plzzzz - I'm on a really truncated time schedule and haven't had much luck with this camera for too long .
TIA
Syndacate said:
Hey,
So I'm making an app that needs to display a bitmap or raw (something where X/Y pixels can be modified, so no compression like a jpg).
There's an Activity which contains only an ImageView, I get the Bitmap from the bundle given in the callback from the camera (it's put into the intent before the Activity starts), then I set it to the ImageView in onCreate of this new Activity (which is basically only an ImageView).
For some reason, when viewing this Activity, the picture is of EXTREMELY low quality. Like, tons of jaggies, like it's a thumbnail or something and is force-scaled up to the screen size. The image isn't really like this, though, when I view it in my gallery it's crystal clear. So why is the quality being dragged down to all hell when I set it in the ImageView? I don't care about the performance constraints, this isn't a production app.
I feel there's some quality control function in the ImageView or something, but I have no idea what. Can somebody tell me the "why" or the "fix" - plzzzz - I'm on a really truncated time schedule and haven't had much luck with this camera for too long .
TIA
Click to expand...
Click to collapse
what other info does the camera intent return, what extras?
alostpacket said:
what other info does the camera intent return, what extras?
Click to expand...
Click to collapse
How do I check?
I used somebody else's tutorial to learn that the URI is in the 'data' of the bundle.
I tried checking earlier by using its to-string, but that just gave me the container size.
Syndacate said:
How do I check?
I used somebody else's tutorial to learn that the URI is in the 'data' of the bundle.
I tried checking earlier by using its to-string, but that just gave me the container size.
Click to expand...
Click to collapse
you probably have the URI to the thumbnail
Post the tutorial you used and some code, shouldn't be too hard to figure out.
alostpacket said:
you probably have the URI to the thumbnail
Post the tutorial you used and some code, shouldn't be too hard to figure out.
Click to expand...
Click to collapse
There's like upteen thousand tutorials that I compiled to make what I have.
I have no "links" anymore.
I got the Intent from the camera in the onActivityResult function after calling the camera. I pulled the bundle from it using the getExtras() function on the intent.
I then passed that intent to the new Intent I made to create my second Activity. I passed it via the putExtras function on the new intent.
In essence, I did;
Code:
Intent in = new Intent();
in.putExtras(incoming_intent_from_camera.getExtras());
And then called my second Activity.
In the onCreate() function of my second Activity, I pull the bitmap data using:
Code:
Bitmap bmp = (Bitmap)getIntent().getExtras().get("data");
There are two things in this Bundle, data (a Bitmap (android.graphics.Bitmap)) and a bitmap-data, which is a boolean.
EDIT:
Yes, it is definitely the URI to the thumbnail, I need the large image URI.
I have a feeling the problem is that it needs the EXTRA_OPTION string, the only issue is, I don't want to save this any place in particular. I'll let the camera save it to the default location on my SDCard. I just want the URI to that full size or something usable.
I can't do:
Code:
intent.putExtra(MediaStore.EXTRA_OPTION, <URI>);
Because I don't have nor want an additional URI to store it... I got to get EXTRA_OPTION to the camera somehow..
Okay, so here's the deal, that apparently nobody was able to help me with ():
- Like alostpacket said, the "data" key in the bundle returned from the camera activity (in the callback) contains the URI to the thumbnail - that's useless unless I'm making an icon or some other small/tiny/low res picture.
I was correct in the fact that it had something to do with putting the EXTRA_OPTION into the extras that I passed off to the camera intent.
This DID come at a price, though. You have to make a temporary place to store the image (you know, because the regular one in the gallery just isn't good enough of or something). And by temporary I kind of mean permanent, it gets overwritten every time (assuming you use the same path), but won't get removed. I am unable to understand this functionality. If somebody could explain it that would be great.
So all in all my intent to the camera looks like this:
Code:
image_path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmp_image.jpg";
File img = new File (image_path);
Uri uri = Uri.fromFile(img);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, PICTURE_REQUEST);
Where image_path is a private class String and PICTURE_REQUEST is a final String (also class level scope) - which can represent any non-0 number, but is unique to the request (think of it as a request ID).
Then, in the callback function, after checking to make sure the request code is PICTURE_REQUEST, and the resultCode was OK:
Code:
Bitmap bmp = BitmapFactory.decodeFile(image_path);
img_view.setImageBitmap(bmp);
img_view.invalidate();
Where image_path is (a String) wherever the image specified as an extra to the camera activity, img_view is an ImageView display element. The invalidate method will redraw the ImageView.
I hope that helps somebody else stuck in the same position I am.
I'm going to leave this question as "unresolved" because there's one thing I still can't figure out. The "EXTRA_OUTPUT" extra passed to the intent seems like a work-around. All that does is define an alternate path to write the file to, then the callback (or whatever) grabs it from there. It's a hack and a half. There has to be a legit way to grab the full quality image taken with the camera. Whether that's accessing the gallery intent or not I'm not sure, but this is definitely a work around. I hope somebody can provide the answer to that, because a lot of tutorials mention the EXTRA_OUTPUT method, and given what it does, I don't believe that is correct.

Adding Bookmarks Are Invisible?

So, I wrote this block of code:
Code:
ContentValues values = new ContentValues();
values.put(BookmarkColumns.BOOKMARK, "1");
values.put(BookmarkColumns.CREATED, "1311170108");
values.put(BookmarkColumns.DATE, "1311170708");
values.put(BookmarkColumns.FAVICON, "favicon");
values.put(BookmarkColumns.TITLE, "XDA");
values.put(BookmarkColumns.URL, "http://forum.xda-developers.com");
values.put(BookmarkColumns.VISITS, "1");
getContentResolver().insert(Browser.BOOKMARKS_URI, values);
When executed, I get no errors. Looking in the browser bookmarks section, the book mark is not there. If i click the Most Visited tab, this shows up and also has the yellow bookmark star next to it, indicating that it is a bookmark. If i click the star to unbook mark it, and click it again, then view the Bookmarks tab, it shows up.
If I use another piece of code to print out all the bookmarks found after I add it, mine shows up
Even with rebooting, they are not showing.
So I ask, why is it that they are not showing up in the bookmarks page of the browser?
I have tried everything and looked around everywhere, and nothing
Thanks!
there is no sanctioned way of adding a bookmark without user input. the normal way would be a call to android.provider.Browser.saveBookmark()
Code:
public static final void saveBookmark(Context c, String title, String url) {
Intent i = new Intent(Intent.ACTION_INSERT, Browser.BOOKMARKS_URI);
i.putExtra("title", title);
i.putExtra("url", url);
c.startActivity(i);
}
other than that dealing with the DB directly would be the only way to add one. try to follow that startActivity to the dialog and see if there is an intent sent to the Browser telling it the DB was updated
killersnowman said:
there is no sanctioned way of adding a bookmark without user input. the normal way would be a call to android.provider.Browser.saveBookmark()
Code:
public static final void saveBookmark(Context c, String title, String url) {
Intent i = new Intent(Intent.ACTION_INSERT, Browser.BOOKMARKS_URI);
i.putExtra("title", title);
i.putExtra("url", url);
c.startActivity(i);
}
other than that dealing with the DB directly would be the only way to add one. try to follow that startActivity to the dialog and see if there is an intent sent to the Browser telling it the DB was updated
Click to expand...
Click to collapse
But, even with restarting the device the book marks are not there. Surely the browser updates the database at that point.
But it also dosnt make sense because if the page was shown in the history, it has the bookmarked indicator next to it
I must do all of this in a fully transparent way. Showing that popup for each one will not do :/
there are a few other columns that are interesting. 'user_entered' which can be '0' or '1'
But I think your best bet is to find the dialog that saveBookmark() calls and analyze its src
Here it is addBookmark()
http://www.java2s.com/Open-Source/A...rowser/com/android/browser/Bookmarks.java.htm
It appears to be static. Why not just call this method?
static void addBookmark(Context context, ContentResolver cr, String url, String name, Bitmap thumbnail, boolean retainIcon)
------nvm i think its package restricted
From something awesome

[Library] StoreBox, an open-source Android library for streamlining SharedPreferences

When getting a value from any preferences, whether private Activity or default shared preferences, you would normally have to get a reference to a SharedPreferences instance, for example using
Code:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(someContext);
Only after that we can start getting/saving the values, such as
Code:
String username = prefs.getString("username", "");
prefs.edit().putString("username", "androiduser").apply();
This can get tedious if the values need to be saved and retrieved from multiple places as the caller is always required to supply the key of the preference, know under what type it is saved, and know what default should be used. This can also become error prone as more keys get used. Putting commonly accessed preferences behind a wrapper is a reasonable solution, but still requires some boilerplate code.
What if however we could define an interface like
Code:
public interface MyPreferences {
@KeyByString("username")
String getUsername();
@KeyByString("username")
void setUsername(String value);
}
for everyone to use in order to save and get values? The caller doesn't need to worry about the key, neither needs to think about what type the key should use, and the process of retrieving/saving is hidden behind a method name with improved semantics.
With StoreBox that becomes reality. Given the above interface definition you can easily create an instance of the interface using
Code:
MyPreferences prefs = StoreBox.create(context, MyPreferences.class);
and you will be able to retrieve/save the value just by calling the defined methods
Code:
String username = prefs.getUsername();
prefs.setUsername("androiduser");
You can read more about the project here, including details on how it can be used and added to a project.
Let me know what you think and whether you find it useful. Thanks!
great! ty
Great work!

Categories

Resources