You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Filip Maj (JIRA)" <ji...@apache.org> on 2013/07/12 04:40:46 UTC

[jira] [Resolved] (CB-3577) Issue on extending cordovaPlugin on execute() method: cordova v 2.7

     [ https://issues.apache.org/jira/browse/CB-3577?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Filip Maj resolved CB-3577.
---------------------------

       Resolution: Won't Fix
    Fix Version/s:     (was: 2.6.0)
         Assignee:     (was: Steve Gill)

This looks to be a problem upgrading a third-party plugin between 2.6 and 2.7. Closing.
                
> Issue on extending cordovaPlugin on execute() method: cordova v 2.7
> -------------------------------------------------------------------
>
>                 Key: CB-3577
>                 URL: https://issues.apache.org/jira/browse/CB-3577
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin Contacts
>    Affects Versions: 2.7.0
>         Environment: Android
>            Reporter: saurabh Trivedi
>              Labels: test
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Hi
> i have downloaded contact_view plugin from github phonegap but on java file there is error on execute method for call back and not getting super class context using "this" key word , this plugin working well for v2.6 and below so now what the changes requires for use this plugin on cordova v2.7 my plugin code is below so pls request to elaborate the changes where needed.i know there is change in execute method and now its return type is boolean but what would be after this , how would we get call back and context ? how to get rid of this issue in v2.7 cordova.
>      public class ContactView extends CordovaPlugin {
> 	
> 	
> 	private static final int PICK_CONTACT = 1;
> 	private String callback;
> 	@Override
> 	public PluginResult execute(String action, JSONArray args, String callbackId) {
> 		startContactActivity();
> 		PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);
> 		mPlugin.setKeepCallback(true);
> 		this.callback = callbackId;
> 		return mPlugin;
> 	}
> 	public void startContactActivity() {
> 		Intent intent = new Intent(Intent.ACTION_PICK);
> 		intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
> 		this.ctx.startActivityForResult((Plugin) this, intent, PICK_CONTACT);
> 	}
> 	@Override
> 	public void onActivityResult(int reqCode, int resultCode, Intent data) {
> 		String name = null;
> 		String number = null;
> 		String email = null;
> 		switch (reqCode) {
> 		case (PICK_CONTACT):
> 			if (resultCode == Activity.RESULT_OK) {
> 				Uri contactData = data.getData();
> 				Cursor c = this.ctx.managedQuery(contactData, null, null, null, null);
> 				if (c.moveToFirst()) {
> 					String ContactID = c.getString(c
> 							.getColumnIndex(ContactsContract.Contacts._ID));
> 					String hasPhone = c.getString(c.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
> 					if (Integer.parseInt(hasPhone) == 1) {
> 						Cursor phoneCursor = this.ctx.managedQuery(
> 										ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
> 										null,
> 										ContactsContract.CommonDataKinds.Phone.CONTACT_ID
> 												+ "='" + ContactID + "'", null,
> 										null);
> 						while (phoneCursor.moveToNext()) {
> 							number = phoneCursor
> 									.getString(phoneCursor
> 									.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
> 						}
> 					}
> 					// get email address
> 					Cursor emailCur = this.ctx.managedQuery( 
> 							ContactsContract.CommonDataKinds.Email.CONTENT_URI, 
> 							null,
> 							ContactsContract.CommonDataKinds.Email.CONTACT_ID + "='" + ContactID + "'", null,null); 
> 						while (emailCur.moveToNext()) { 
> 						    // This would allow you get several email addresses
> 					            // if the email addresses were stored in an array
> 						    email = emailCur.getString(
> 					                      emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
> 					 	    //String emailType = emailCur.getString(
> 					          //            emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); 
> 					 	} 
> 					 	emailCur.close();
> 					name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME));
> 					JSONObject contactObject = new JSONObject();
> 					try {
> 						contactObject.put("name", name);
> 						contactObject.put("phone", number);
> 						contactObject.put("email", email);
> 					} catch (JSONException e) {
> 						e.printStackTrace();
> 					}
> 					this.success(new PluginResult(PluginResult.Status.OK,
> 							contactObject), this.callback);
> 				}
> 			}
> 			break;
> 		}
> 	}
> 		
> 	}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira