Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
BlackBerry Development Advisor
Posts: 172
Registered: ‎10-25-2010
My Device: Not Specified

Re: Enable Share button in context menu

[ Edited ]

@mdd Can you post the code that generated this output as well.

 

Thanks

Julian

Developer
Posts: 229
Registered: ‎03-14-2012
My Device: PlayBook 2.0
My Carrier: AT&T

Re: Enable Share button in context menu

Nothing happens if I tab the button and if I select text there is no option in the context menu to share it.

 

What is wrong with the code?

 

import qnx.events.InvokeEvent;
import qnx.invoke.*;

import qnx.fuse.ui.core.InvokeActionItem;
import qnx.fuse.ui.core.ActionSet;
import qnx.fuse.ui.core.ActionBase;

import flash.utils.ByteArray;



var ba:ByteArray = new ByteArray();
ba.writeUTFBytes("Some text to share");

var openapp:Button = new Button();
var invokeItem:InvokeActionItem = new InvokeActionItem(InvokeAction.SHARE,"text/plain","sys.bbm.sharehandler",ba);
var actionSet:ActionSet = new ActionSet(new <ActionBase>[invokeItem]);
var actions:Vector.<ActionSet> = new <ActionSet>[actionSet];

openapp.contextActions = actions;

addChild(openapp); 
BlackBerry Development Advisor
Posts: 172
Registered: ‎10-25-2010
My Device: Not Specified

Re: Enable Share button in context menu

Why are you setting "sys.bbm.sharehandler" as the uri?

I also just want to make sure that you are long pressing on the button to get the context menu to show up.
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Enable Share button in context menu

Also, does he really need to set the perimeter?
Developer
Developer
Posts: 227
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT

Re: Enable Share button in context menu

query invoke targets code:

		private function checkNext():void
		{
			if ( _queue.length > 0 )
			{
				var dli:DownloadListItem = _queue[0] as DownloadListItem;
				
				Invoker.getInvokableActions( '*/*', encodeURI( dli.item.file.url ), haveQueryResponse );
			}
			else
			{
				dispatchEvent( new Event( Event.COMPLETE ) ); 
			}

			function haveQueryResponse( actions:Array ):void
			{
				var dli:DownloadListItem = _queue[0] as DownloadListItem;
				var item:DownloadItem = dli.item;

				item.open = actions.length > 0;
				
				trace( "   haveQueryResponse:", item.label, item.open );
				
				var actionItem:InvokeActionItem = new InvokeActionItem(  null, '*/*', encodeURI( item.file.url ) );
				{
					actionItem.addEventListener( Event.COMPLETE, checkComplete );
				}
			}

			function checkComplete( e:Event ):void
			{
				var invokeActionItem:InvokeActionItem = e.target as InvokeActionItem;
				{
					invokeActionItem.removeEventListener( e.type, checkComplete );
					
					var actions:Vector.<InvokableAction> = invokeActionItem.getInvokableActions();

					if ( actions )
					{
						var item:DownloadListItem = _queue[0] as DownloadListItem;			

						trace( "       checkComplete:", item.item.label, invokeActionItem.action, "found:", actions.length );
						
						for each( var action:InvokableAction in actions )			
						{
							trace( '              action: ' + action.label + ' icon: ' + action.icon, action.invokeAction );							
						}
						if ( actions.length > 0 )
						{
							item.actionItem = invokeActionItem;
						}
					}
				}
				_queue.shift();
					
				checkNext();
			}
			
		}

 

code to query:

		public static function getInvokableActions( mimeType:String, uri:String, handler:Function = null, actions:Array = null ) : void			
		{
//			InvokeManager.DEBUG = true;

			if ( InvokeManager.invokeManager.hasEventListener( InvokeQueryTargetEvent.SUCCESS ) )
			{
				trace( "Invoker.getInvokableActions:", "busy..." );
			}
			else
			{
				actions ||= [ InvokeAction.OPEN, InvokeAction.VIEW ];
				
				InvokeManager.invokeManager.addEventListener( InvokeQueryTargetEvent.SUCCESS, onQuerySuccess );
				
				InvokeManager.invokeManager.queryInvokeTargets( mimeType, uri, null, InvokeTargetOptions.ALL );			
			}
			
			function onQuerySuccess( event : InvokeQueryTargetEvent ) : void			
			{			
				InvokeManager.invokeManager.removeEventListener( InvokeQueryTargetEvent.SUCCESS, onQuerySuccess );

				var found:Array = new Array();
				var action	: ActionQuery;			
				var target	: InvokeTarget;

				trace( "getInvokableActions:", mimeType, uri, actions );

				for each( action in event.actions )			
				{
					trace( '   action: ' + action.action + ' ' + action.label + ' = ' + action.defaultTarget, "nTargets:", action.targets.length );

					if ( actions.indexOf( action.action ) >= 0 )
					{
						found.push( action );
						
						for each( target in action.targets )				
						{				
							trace( "       target:", target.target, "label:", "'" + target.label + "'", "Type:", target.type, "icon:", target.icon );
						}
					}
				}
				
				if ( handler is Function ) handler( found );
			}			
		}
BlackBerry Development Advisor
Posts: 172
Registered: ‎10-25-2010
My Device: Not Specified

Re: Enable Share button in context menu

@mdd I would try passing null for the mimeType.

 

You are already passing a uri, so the mimeType is implied.

BlackBerry Development Advisor
Posts: 172
Registered: ‎10-25-2010
My Device: Not Specified

Re: Enable Share button in context menu

Perimeter should not be set. It should be left null in all cases.
Developer
Developer
Posts: 227
Registered: ‎01-17-2012
My Device: PB
My Carrier: ATT

Re: Enable Share button in context menu

Julian;

 

I've set mimeType to null (in queryInvokeTargets and new InvokeActionItem) - no change:

 

file is jpg

   - queryInvokeTargets returns actions for: Share, Set As, Open, View and nfc.writetag.  all are APPLICATION or CARD.

   - getInvokableActions return only Share and Set As.

 

I should be able to Open/View from the contextMenu on a long press.

Developer
Posts: 229
Registered: ‎03-14-2012
My Device: PlayBook 2.0
My Carrier: AT&T

Re: Enable Share button in context menu

Please, can someone upload a full working example how to enable the "share button" in the context menu?
I just can't get it to work! Already wasted 2 days on this :smileysad:

BlackBerry Development Advisor
Posts: 172
Registered: ‎10-25-2010
My Device: Not Specified

Re: Enable Share button in context menu

@ Vibes

 

I believe we already have a couple of times now. Here is another one.

 

 

import qnx.events.InvokeEvent;
import qnx.invoke.*;

import qnx.fuse.ui.core.InvokeActionItem;
import qnx.fuse.ui.core.ActionSet;
import qnx.fuse.ui.core.ActionBase;

import flash.utils.ByteArray;



var ba:ByteArray = new ByteArray();
ba.writeUTFBytes("Some text to share");

var openapp:Button = new Button();
var invokeItem:InvokeActionItem = new InvokeActionItem(null,"text/plain",null,ba);
var actionSet:ActionSet = new ActionSet(new <ActionBase>[invokeItem]);
var actions:Vector.<ActionSet> = new <ActionSet>[actionSet];

openapp.contextActions = actions;

addChild(openapp);