Gdata map Api in android - android

i am trying to implement gdata map api in my android project.. but i am unable to solve this error
"java.lang.VerifyError: com.google.gdata.client.media.MediaService"
i am using all the libraries required to implement gdata apis
MapsService myService = new MapsService("createMap"); error is coming due to this line
is there any clue..
thnx..
i am trying with following code
//
**MapsService myService = new MapsService("createMap");**
try {
// Replace username and password with your authentication credentials
myService.setUserCredentials("username","password");
createMap(myService);
} catch(AuthenticationException e) {
System.out.println("Authentication Exception");
} catch(ServiceException e) {
System.out.println("Service Exception: " + e.getMessage());
} catch(IOException e) {
System.out.println("I/O Exception");
}
}
public static MapEntry createMap(MapsService myService)
throws ServiceException, IOException {
// Replace the following URL with your metafeed's POST (Edit) URL
// Replace userID with appropriate values for your map
final URL editUrl = new URL("http://maps.google.com/maps/feeds/maps/userID/full");
MapFeed resultFeed = myService.getFeed(editUrl, MapFeed.class);
URL mapUrl = new URL(resultFeed.getEntryPostLink().getHref());
// Create a MapEntry object
MapEntry myEntry = new MapEntry();
myEntry.setTitle(new PlainTextConstruct("Demo Map"));
myEntry.setSummary(new PlainTextConstruct("Summary"));
myEntry.getAuthors().add(new Person("My Name", null, "username"));
return myService.insert(mapUrl, myEntry);
}

You have to add "servlet.jar, activation.jar, mail.jar" In your source code

Related

android youtube data api

I am trying to find the details of a youtube video through its ID (example ->
yb7E4lQIaZI). I read that if we just want the details we can use the api_key from the developer console. if we want to do operations such as upload a video we need to use oauth. I just want to go with the firstcase. i just need the details of the video like thumnail url and title which i want to show in a listview.
I am trying to do this with the use of my api_key but i cant make it to work.The last line (system.out.println) is not printing anything. The code i have written is below
try {
YouTube youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new
HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
}
}).setApplicationName("my_project").build();
HashMap<String, String> parameters = new HashMap<>();
parameters.put("part", "snippet,contentDetails,statistics");
parameters.put("id", "yb7E4lQIaZI");
YouTube.Videos.List videosListByIdRequest = youtube.videos().list(parameters.get("part").toString());
videosListByIdRequest.setKey(MY_API_KEY_FROM_DEVELOPER_CONSOLE);
if (parameters.containsKey("id") && parameters.get("id") != "") {
videosListByIdRequest.setId(parameters.get("id").toString());
}
VideoListResponse response = videosListByIdRequest.execute();
System.out.println(response);
} catch (GoogleJsonResponseException e) {
e.printStackTrace();
System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
When i run the debug it exits after the line 'VideoListResponse response = videosListByIdRequest.execute();' and doesnot go to the line 'System.out.println(response)'.
The app doesnot crash or show any error, it just doesnt go to the 'system.out.print' line
Did you check if you have added internet permission in your manifest.
<uses-permission android:name="android.permission.INTERNET" />

How to push data to my index using algolia android

I have a problem pushing data to my index. My code is as follows:
Client client = new Client("APP_ID", "SEARCH_ID");
Index myIndex = client.initIndex("test");
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject()
.put("name", "Jimmie")
.put("username", "Barninger")
} catch (JSONException e) {
e.printStackTrace();
}
myIndex.addObjectAsync(jsonObject, null);
However nothing happens, and no data is visible in my dashboard. What am I doing wrong?
I had to change the api keys which previously was SEARCH_ID. I changed it to my ADMIN_API_KEY:
Client client = new Client("APP_ID", "ADMIN_API_KEY");
This is because the search-only API key can only be used for searching, while the Admin API key can change, delete or add an object.
The full code is now:
Client client = new Client("APP_ID", "ADMIN_API_KEY");
Index myIndex = client.initIndex("test");
JSONObject object = null;
try {
object = new JSONObject()
.put("username", "Jimmie")
.put("name", "Barninger");
} catch (JSONException e) {
e.printStackTrace();
}
// myIndex.addObjectAsync(object, "myID", null);
myIndex.addObjectAsync(object, "id", null);
In order to understand more, please replace the addobjectAsync line with something like this:
index.addObjectAsync(object, new CompletionHandler() {
#Override
public void requestCompleted(JSONObject content, AlgoliaException error) {
if (error != null) {
// Check what is the error Here
}
}
}

How to create and send Bye message from client to server in jainsip android?

I have tried jainsip example in Mobicents restcomm-android-sdk.Its worked for me but i am not able create bye message from client side properly.
I created a Bye Message class like this
public class Bye {
public Request MakeRequest(SipManager sipManager) throws ParseException,
InvalidArgumentException {
AddressFactory addressFactory = sipManager.addressFactory;
SipProvider sipProvider = sipManager.sipProvider;
MessageFactory messageFactory = sipManager.messageFactory;
HeaderFactory headerFactory = sipManager.headerFactory;
// Create addresses and via header for the request
Address fromAddress = addressFactory.createAddress("sip:"
+ sipManager.getSipProfile().getSipUserName() + "#"
+ sipManager.getSipProfile().getRemoteIp());
fromAddress.setDisplayName(sipManager.getSipProfile().getSipUserName());
Address toAddress = addressFactory.createAddress("sip:"
+ sipManager.getSipProfile().getSipUserName() + "#"
+ sipManager.getSipProfile().getRemoteIp());
toAddress.setDisplayName(sipManager.getSipProfile().getSipUserName());
Address contactAddress = sipManager.createContactAddress();
ArrayList<ViaHeader> viaHeaders = sipManager.createViaHeader();
URI requestURI = addressFactory.createAddress(
"sip:" + sipManager.getSipProfile().getRemoteEndpoint())
.getURI();
// Build the request
CallIdHeader callIdHeader = sipManager.sipProvider.;
final Request request = messageFactory.createRequest(requestURI,
Request.BYE, sipProvider.getNewCallId(),
headerFactory.createCSeqHeader(1l, Request.BYE),
headerFactory.createFromHeader(fromAddress, "c3ff411e"),
headerFactory.createToHeader(toAddress, null), viaHeaders,
headerFactory.createMaxForwardsHeader(70));
// Add the contact header
request.addHeader(headerFactory.createContactHeader(contactAddress));
ExpiresHeader eh = headerFactory.createExpiresHeader(300);
request.addHeader(eh);
// Print the request
System.out.println(request.toString());
return request;
// Send the request --- triggers an IOException
// sipProvider.sendRequest(request);
// ClientTransaction transaction = sipProvider
// .getNewClientTransaction(request);
// Send the request statefully, through the client transaction.
// transaction.sendRequest();
}
}
Call it From SipManager class as
public void disconnectCall() throws NotInitializedException {
// TODO Auto-generated method stub
if (!initialized)
throw new NotInitializedException("Sip Stack not initialized");
this.sipManagerState = SipManagerState.BYE;
Bye byeRequest = new Bye();
Request r=null ;
try{
r = byeRequest.MakeRequest(this);//byeRequest.MakeRequest(SipManager.this);
final ClientTransaction transaction = this.sipProvider
.getNewClientTransaction(r);
Thread thread = new Thread() {
public void run() {
try {
transaction.sendRequest();
} catch (SipException e) {
e.printStackTrace();
}
}
};
thread.start();
} catch (TransactionUnavailableException e) {
e.printStackTrace();
}catch (InvalidArgumentException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
I have got 481 error code as response.I think I have missed the current callid field in the bye message.I have searched for it but not found from sipmanager class.pls help.
Nidhin,
BYE messages are always inside a SIP dialog, so you don't have to create a new message from scratch. Instead, you just need to get ahold of the dialog you want to terminate, create a request of type BYE from that and send it. JAIN will take care of the rest.
For an example, you can check the code at the Mobicents restcomm-android-sdk repo, method sendByeClient():
https://github.com/Mobicents/restcomm-android-sdk/blob/master/sipua/src/main/java/org/mobicents/restcomm/android/sipua/impl/SipManager.java#L931
Please also keep in mind that the JAIN SIP example has been obsoleted by Messenger example that uses the Restcomm Android Client SDK which offers a simpler API. Here's its code for your reference:
https://github.com/Mobicents/restcomm-android-sdk/tree/master/Examples/restcomm-messenger

Unclear instruction in Google Documents List API "Creating or uploading spreadsheets"

I'm trying to create a spreadsheet via my android app. So far I've been only successful in creating an empty text document. Google's Spreadsheet API instructs me to follow Google Documents List API in order to create a spreadsheet document in Google Drive. In Google Documents List API it says:
To create a new, empty spreadsheet, follow the instructions in
Creating a new document or file with metadata only. When doing so, use
a category term of http://schemas.google.com/docs/2007#spreadsheet.
In the link above I've found the next .NET code:
using System;
using Google.GData.Client;
using Google.GData.Documents;
namespace MyDocumentsListIntegration
{
class Program
{
static void Main(string[] args)
{
DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1");
// TODO: Authorize the service object for a specific user (see Authorizing requests)
// Instantiate a DocumentEntry object to be inserted.
DocumentEntry entry = new DocumentEntry();
// Set the document title
entry.Title.Text = "Legal Contract";
// Add the document category
entry.Categories.Add(DocumentEntry.DOCUMENT_CATEGORY);
// Make a request to the API and create the document.
DocumentEntry newEntry = service.Insert(
DocumentsListQuery.documentsBaseUri, entry);
}
}
}
I've used this code to try and create a spreadsheet, but only the third variant worked (using DocsService, without adding Category and using feedUrl URL object).
Here's part of my working code (upload() is being called when user clicks a button):
private void upload() {
SpreadSheetAsyncTask sprdSheetAsyncTsk = new SpreadSheetAsyncTask();
sprdSheetAsyncTsk.execute();
}
public class SpreadSheetAsyncTask extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
spreadSheetService = new SpreadsheetService("Salary_Calculator");
docService = new DocsService("Salary_Calculator");
try {
spreadSheetService.setUserCredentials(USERNAME, PASSWORD);
docService.setUserCredentials(USERNAME, PASSWORD);
URL feedUrl = new URL(
"https://docs.google.com/feeds/default/private/full/");
URL tmpFeedUrl = new URL(
"https://spreadsheets.google.com/feeds/worksheets/key/private/full");
DocumentEntry entry = new DocumentEntry();
Calendar timeRightNow = GregorianCalendar.getInstance();
entry.setTitle(new PlainTextConstruct(
"Salary Calculator Spreadsheet "
+ timeRightNow.get(Calendar.DAY_OF_MONTH) + "/"
+ (timeRightNow.get(Calendar.MONTH) + 1) + "/"
+ timeRightNow.get(Calendar.YEAR)));
// Category object = new Category("spreadsheet",
// "http://schemas.google.com/docs/2007#spreadsheet");
//
//
// entry.getCategories().add(object);
/*
* TODO TEST AREA
*/
entry = docService.insert(feedUrl, entry);
/*
* TODO TEST AREA
*/
} catch (AuthenticationException e) {
cancel(true);
loginDialog("Wrong username or password");
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (ServiceException e) {
cancel(true);
loginDialog("Wrong username or password");
} catch (Exception e) {
loginDialog("Wrong username or password");
}
return null;
}
}
The non working code uses the category object object (as shown in the code comment) above and uses entry = spreadSheetService.insert(feedUrl, entry);
My question is - what did they want me to do when they wrote use a category term of http://schemas.google.com/docs/2007#spreadsheet?

Android twitter tweet with image [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can we post image on twitter using twitter API in Android?
I am working in an android application and I want to tweet a message and a picture to twitter. I am able to tweet only tweets to twitter by the code :
String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");
AccessToken a = new AccessToken(token, secret);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(Constants.CONSUMER_KEY,
Constants.CONSUMER_SECRET);
twitter.setOAuthAccessToken(a);
try {
**twitter.updateStatus("New tweet");**
twitter.//Which property of twitter should I use to tweet an image and //message
} catch (TwitterException e) {
// TODO Auto-generated catch block
Log.e("Errorssssssssssssss", e.toString());
}
How do I include an image as well?
refer to http://www.londatiga.net/it/how-to-post-twitter-status-from-android/, use twitter4j library
public void uploadPic(File file, String message) throws Exception {
try{
StatusUpdate status = new StatusUpdate(message);
status.setMedia(file);
mTwitter.updateStatus(status);}
catch(TwitterException e){
Log.d("TAG", "Pic Upload error" + e.getErrorMessage());
throw e;
}
}
where mTwitter is an instance of Twitter class
Make sure you are using latest version of twitter4j-core jar file.
U can try example which comes with Twitter4j Library.Following code will help u
public final class TwitpicImageUpload {
/**
* Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [message]
*
* #param args message
*/
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Usage: java twitter4j.examples.media.TwitpicImageUpload [API key] [image file path] [message]");
System.exit(-1);
}
try {
Configuration conf = new ConfigurationBuilder().setMediaProviderAPIKey(args[0]).build();
ImageUpload upload = new ImageUploadFactory(conf).getInstance(MediaProvider.TWITPIC);
String url;
if (args.length >= 3) {
url = upload.upload(new File(args[1]), args[2]);
} else {
url = upload.upload(new File(args[1]));
}
System.out.println("Successfully uploaded image to Twitpic at " + url);
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to upload the image: " + te.getMessage());
System.exit(-1);
}
}
}
Download Twitter4j Library look for more examples there.

Categories

Resources