locked
Share charm is displaying "App Can't share right now" when executed from the package

    Question

  • Hi

    when I am setting data to the "Data Request" object I am using an asynchronous call to fetch the data. Before data is fetching from the application share charm is displaying message like "App Can't share right now". Please find the code below

    RegisterEvents() { m_evtDataRequestedEventToken = DataTransferManager::GetForCurrentView()->DataRequested += ref new TypedEventHandler<DataTransferManager^, DataRequestedEventArgs^>(this, &HomePage::OnDataRequested); } void HomePage::OnDataRequested(DataTransferManager^ sender, DataRequestedEventArgs^ e) { // done some more error handling here in this method GetShareContent(e->Request); } bool HomePage::GetShareContent(DataRequest^ request) { m_shareContentDeferral = request->GetDeferral(); downloadfile(itemname,itemid); } // below method will be called from the back ground thread once the download is completed void HomePage::FillStorageData(String^ fileName) { IAsyncOperation<StorageFile^>^ storageFileAsync = StorageFile::GetFileFromPathAsync(fileName); task<StorageFile^>(storageFileAsync).then([=](task<StorageFile^> getFileTask){ try { if(m_shareContentDeferral != nullptr && m_shareContentRequest !=nullptr) { auto storageFile = getFileTask.get(); auto storageItems = ref new Vector<IStorageItem^>(); storageItems->Append(storageFile); m_shareContentRequest->Data->SetStorageItems(storageItems);

    m_shareContentDeferral -> complete(); } }


    The above code is working perfectly when the application is executed from visual studio but in package it is showing the message "App Can't share right now"
    • Edited by Raja KPV Wednesday, December 26, 2012 12:52 PM
    Wednesday, December 26, 2012 12:43 PM

All replies

  • Hi,

    Did you check the if the storageFile is not empty.

    Here is the sample of sharing content, there is a scenario for files.
    http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Source-App-d9bffd84
    Hope it helps.
     
    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 27, 2012 7:16 AM
  • Hi Jesse Jiang,

    Thanks for responding to my question,

    in the above issue what I observed is getsharecontent method is calling the downloadfile api and then it is throwing the message. The download file api calls background thread to download the content and in the callback(download completion) I am calling the fillstorage data method to read the file and then I am completing the deferral.

    But the share charm is not waiting until the download is completed and throwing the message.

    Regards

    Raja PV


    raja

    • Proposed as answer by Jesse Jiang Tuesday, January 01, 2013 5:31 AM
    Thursday, December 27, 2012 7:33 AM
  • Yes, the download operator should be finished, so that we can share the file.

    We should store the download file in temp local path.

    I think we can close this thread.

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, January 01, 2013 5:31 AM
  • Hi Jesse jiang

    Thanks for your interest in answering the question

    I had used delegate to download the content with a provider deferral but still share charm is throwing the error " Error occurred while uploading a file to the target application".

    Code that I had written is as follows.

    RegisterEvents()
    {
     m_evtDataRequestedEventToken = DataTransferManager::GetForCurrentView()->DataRequested += 
    		ref new TypedEventHandler<DataTransferManager^, DataRequestedEventArgs^>(this, &OnDataRequested);
    }
    void OnDataRequested(DataTransferManager^ sender, DataRequestedEventArgs^ e)
    {
    // done some more error handling here in this method
    GetShareContent(e->Request);
    }
    
    bool GetShareContent(DataRequest^ request)
    {
    m_shareContentDeferral = request->GetDeferral();	
    requestData->Properties->FileTypes->Append(StandardDataFormats::StorageItems);
    		requestData->SetDataProvider(StandardDataFormats::StorageItems, ref new DataProviderHandler(this, &GetStorageItemToShare));
    }
    
    void GetStorageItemToShare(Windows::ApplicationModel::DataTransfer::DataProviderRequest^ request)
    {
    m_shareDataProviderDeferral = request->GetDeferral();
    downloadfile(itemname,itemid);
     }
    
    // below method will be called from the back ground thread once the download is completed
    
    void FillStorageData(String^ fileName)
    {
    IAsyncOperation<StorageFile^>^ storageFileAsync = StorageFile::GetFileFromPathAsync(fileName);
    
    		task<StorageFile^>(storageFileAsync).then([=](task<StorageFile^> getFileTask){	
    			try
    			{
    				if(m_shareContentDeferral != nullptr && m_shareContentRequest !=nullptr)
    				{
    					auto storageFile = getFileTask.get();
    					auto storageItems = ref new Vector<IStorageItem^>();
    					storageItems->Append(storageFile);
    					m_shareContentRequest->Data->SetStorageItems(storageItems);
    
    m_shareDataProviderDeferral -> complete();	
    }
    }
    

    Regards

    Raja PV


    raja


    • Edited by Raja KPV Tuesday, January 08, 2013 6:42 AM
    Wednesday, January 02, 2013 4:59 AM
  • Hi

    Can somebody please let me know what is wrong with the above code


    raja

    Wednesday, January 09, 2013 10:09 AM