Open Maps and show a place. - Android Software Development

Hello, im trying to program an intent for open google maps and show a place.
I want to select the place by coordinates.
I have tested
Code:
String uri = "geo:0,0?q="+address;
context.startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
It works fine and show the location of the address with a marker
But using coordinates:
Code:
String uri = "geo:"+ lat+ "," +log;
context.startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
Is the zone is shown but there's no marker for showing the exact place.
how can I place the marker in the intent (with a label if possible)
Thanks in advance.

i take it you've seen this http://developer.android.com/guide/appendix/g-app-intents.html
it looks like it says that the use of the geo tag is underdevelopment at the moment. it might just be that the implementation of this uri is broken.

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=37.423156,-122.084917 (" + name + ")");
startActivity(intent);

Related

Click on Notification does not work as expected... (see screencast!):(

Hi guys,
first of all - Merry Christmas!!!
I have a strange problem here and spent too many hours figuring out what the problem might be. I definitely need your help here now... I'm pretty sure this is very easy to fix... if you know how...
I develop a little free app for German O2 customers so that they can send their 50 free Web-SMS directly from their Android phone and not only via web interface like O2 wants them to. These SMS are sent in the background using a service. This service generates notifications (e.g. Message sent successfully, Login successful/failed,...)
When I click on that notification the app should open and then display the notification message. This works pretty fine as long as the app is visible (foreground/active). When putting the app into the background it's getting launched as well, but it doesn't display the message... then, when I hold down the HOME-Key and select the app... the message gets displayed.
See the following video... to show you what I mean...
http://dl.dropbox.com/u/1676562/NotificationIssue.mov
I'm pretty sure it has something to do with the Fflags for my intent, so here's my code:
Setting the notification:
Code:
// The PendingIntent to launch our activity if the user selects this
// notification
final Intent notificationIntent = new Intent(ManagerFactory
.getMasterActivity(), MailerActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
Log.d(TAG, "Set new message to Notification: " + p_message);
notificationIntent
.putExtra(Constants.NOTIFICATION_EXTRA_KEY, p_message);
Log.d(TAG, "Setting requestCodeToFixNotificationBug: "
+ s_requestCodeToFixNotificationBug);
final PendingIntent contentIntent = PendingIntent.getActivity(
ManagerFactory.s_service, s_requestCodeToFixNotificationBug++,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(ManagerFactory.s_service, p_tickerText,
p_message, contentIntent);
Reacting on the incoming intent:
Code:
/*
* (non-Javadoc)
*
* @see android.app.Activity#onNewIntent(android.content.Intent)
*/
@Override
protected final void onNewIntent(final Intent p_intent) {
// when called via notification, get the extras
Log.d(TAG, "Called onNewIntent...");
final Bundle extras = p_intent.getExtras();
Log.d(TAG, "Extra: " + extras);
if (extras != null
&& extras.getString(Constants.NOTIFICATION_EXTRA_KEY) != null
&& !extras.getString(Constants.NOTIFICATION_EXTRA_KEY).trim()
.equalsIgnoreCase("")) {
Log.d(TAG, "Extra:"
+ extras.getString(Constants.NOTIFICATION_EXTRA_KEY));
this.showLongMessage(extras
.getString(Constants.NOTIFICATION_EXTRA_KEY));
}
}
Would be great if someone was able to help me...
Sascha
Does onNewIntent get called? If it does, try stepping through the code with a debugger. Also try setting a unique value to the Intent's data field like System.currentTimeMillis().
Doing this fixed a similar issue for me.

[Q] Easy string initialize question

Hi,
I am reading a book on Android development. In one of the source code examples the author uses the construct:
String tt = **;
I assume he is initializing his new string to empty, but I have never seen this before and just want to be sure. There is probably a more detailed meaning.
Google search doesn't find anything like this. Can someone confirm what this means?
Thanks for any info or pointers to the definition.
Barry.
Uh, that's an error.
// Initialize String, 2 ways
String tt = null; // I always use this
String tt = ""; // empty string can be unpredictable

Trouble with database

Hello all! I'm somewhat new to Android development, I'm using eclipse to do all of my development. Right now I am working on an "away message text" application. I am having trouble with database query returning a string of the first index of data. Here is my code where i am trying to pull data from the database. This is being done inside my ReceiveText class, which extends BroadcastReceiver.
mDbHelper = new TextsDbAdapter(context);
mDbHelper.open();
getText = mDbHelper.fetchText(0);
message = getText.getString(getText.getColumnIndex(mDbHelper.KEY_BODY)).toString();
The error that I am getting is Cursor index out of bounds...any recommendations? Thanks!
you always start out of bounds.... you have to moveToFirst() first...
Thanks. Would I moveToFirst() before I fetchText()?
you're probably going to have to change how the fetchText method is implemented.
you'll probably want something like
Code:
public String fetchText(int id){
Cursor c = getContentResolver().query( uri,
new String[] { <name_of_text_column> } ,
"_id == " + id, null, null);
String text = null;
if( c != null ){
if( c.moveToFirst() ){
text = c.getString( c.getColumnIndex( <name_of_text_column> ) );
}
c.close();
}
return text;
}
Thanks. The method I have for fetchText returns a Cursor, however I made another method that returns a string, similar to what you recommended. For some reason, there is something wrong with the rowid sending in, I want to just get the first one, if I'm not mistaken, wouldn't it be 0? I have a seperate ReceiveText.java class, which extends Broadcast Receiver. The part where the messages are stored into the database is very similar to androids notepad demo. When a text is received, I want the ReceiveText class to query the database and just pull the first text that was actually stored into the database. I have 3 columns, KEY_ROWID, KEY_TITLE, and KEY_BODY. For some reason there is an issue when trying to query the database from the ReceiveText class. Any ideas that would make better sense or be easier to implement? Any help is much appreciated.
oh, right. I wasn't paying attention and for some reason I thought it was returning a string. I see now that it's obviously a cursor..
what you are doing sounds fine but you sure really look at the database on the phone/emulator.
open up adb and type
Code:
sqlite3 /data/data/<name_of_app>/databases/<name_of_db>
then you can do
Code:
select * from <name_of_table>
personally, I find it way easier to read if you change the mode with a ".mode line" command(the dot is important).
that should give you a good idea of why it is not working properly.
How do I open up the adb? I looked online, and it says i can run it through command line, or terminal since I use ubuntu, but I'm not sure exactly how to open it. Apologies for my noobness with android development i'm trying to learn!
if you're running it on a phone/tablet, you'll have to set up the adb drivers
but if you're just using the emulator, you're fine
Code:
cd /<path_to_sdk>/platform-tools/
./adb devices ##this should list the device. if not you have a problem.
./adb shell
and now you can execute commands on the device, like sqlite3
Awesome, I got that to work, and i can see the three "texts" that i've added to the database...looks like this...
1|Sleeping|Sleeping...text you when I wake up.
2|Driving|Driving right now...text you when I'm done.
3|Xbox|Playing xbox...text you later.
So this means that my database works. The numbers 1,2, and 3 are the KEY_ROWID, sleeping, driving, and xbox are the KEY_TITLE, and the third part is the KEY_BODY.
For some reason the ReceiveText class is having trouble pulling this information from the database, I really think it has something to do with when i Query the database, it asks for a columnindex, and i am putting a 0 as the parameter. Any ideas? Thanks again for all your help. It's a great learning process.
yeah, there doesn't seem to be a column with _id == 0
that is strange. when you defined it did you use "integer primary key autoincrement"? This should start at 0, I believe.. maybe you deleted your first entry at some point?
try it with 1 and see if that works.
Man, thanks so much for your help...it works! Here is how I did it from the ReceiveText class.
mDbHelper = new TextsDbAdapter(context);
mDbHelper.open();
getText = mDbHelper.fetchText(1);
message = getText.getString(2).toString();
getText is a Cursor type, and message is a String type.
I really appreciate the help, I understand a lot more now. My next step is to set the text to use without having to specify from the ReceiveText class...any suggestions? I was thinking adding another column in the database that would hold either a 1 or 0, and if it is selected, it updates the database and changes that field to a 1, then the ReceiveText class will query the database to return the field that has the 1...make sense? lol
Just to clear this up a bit for those still a little fuzzy:
Code:
Cursor c = db.query(TABLE_NAME3, new String[] {NAMESHORT, LAPTIME, LAPNUMBER}, null ,null, null, null, orderBy);
The column indexes are what you have in the "new String[]" area whether you have 1 or 50 items. So, NAMESHORT is index 0, LAPTIME is index 1 and LAPNUMPER is index 2. It's NOT the column number of where it is in the table
Just a personal preference of mine, but I code all this in the database methods and return what I need from there. Seeing hard-coded numbers in a program always bothers me. Instead of returning cursors I'll return a StringBuilder or ArrayList or whatever. Just sayn'

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

[HELP] 'Open With' File Manager

I'm in the process of creating a file manager, however I've stumbled across a problem regarding opening/executing files. At the moment I'm opening files like this :
Code:
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(Intent.createChooser(intent, "Open With"));
But dialog that shows doesn't contain the applications that I know would open the file type and sometimes it doesn't show any 'Open With' dialog, it just tried to open the file using a PDF reader!?
Do I have to manually figure out what applications are compatible with certain files? That would be a massive headache...
Thanks.
http://stackoverflow.com/questions/2916108/android-open-a-pdf-from-my-app-using-the-built-in-pdf-viewer?lq=1
Look down about half way down the page, see if that helps out.
zalez said:
http://stackoverflow.com/questions/2916108/android-open-a-pdf-from-my-app-using-the-built-in-pdf-viewer?lq=1
Look down about half way down the page, see if that helps out.
Click to expand...
Click to collapse
Thanks, but that's not really what I'm looking for. 'build.prop' for example, a text document but because of its extension '.prop' the Intent type gets set to 'null' and when its null Android just opens it using Adobe PDF Reader as default which I DO NOT want. I want it to list the applications that CAN open a text file.
Gotcha. What about:
http://helloworldcodes.blogspot.com/2011/10/android-open-folder-with-default.html
Or
http://indyvision.net/2010/03/android-using-intents-open-files/
First comment on this blog
Thanks for that! Turns out the problem was 'intent.setDataAndType' I wasn't setting any data. I've still had to filter a few extensions though.
Code:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
String type;
if(selected.getExtension().contentEquals("prop") || selected.getExtension().contentEquals("rc") || selected.getExtension().contentEquals("conf") || selected.getExtension().contentEquals("sh")){
type = "text/plain";
}else{
MimeTypeMap mime = MimeTypeMap.getSingleton();
type = mime.getMimeTypeFromExtension(selected.getExtension());
if(type == null)
type = "*/*";
}
intent.setDataAndType(Uri.fromFile(new File(selected.getPath())),type);
startActivity(Intent.createChooser(intent, "Open With"));

Categories

Resources