Pmovil / CN1WindowsPort

Windows RT port to Codename One
MIT License
6 stars 3 forks source link

Open app #18

Closed luiz04nl closed 8 years ago

luiz04nl commented 8 years ago

I did all the steps but when the app is open on a black screen and nothing else happens, most lack any step or something went wrong? I am not knowledgeable world with programming windows native phone

FabricioCabeca commented 8 years ago

It is hard to tell you what is going wrong, I would double check steps 5 and 6 ...

luiz04nl commented 8 years ago

all steps are correct, I believe that explain why the two files then do not compile correctly will better understand the problem:

# App.xaml.cs

using System; using System.Diagnostics; using System.Resources; using System.Windows; using System.Windows.Markup; using System.Windows.Navigation; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; using Main.Resources; using Parse; using com.parse4cn1.nativeinterface; using System.Collections.Generic;

namespace Main { public partial class App : Application { public static PhoneApplicationFrame RootFrame { get; private set; } public App() { UnhandledException += Application_UnhandledException;

        // [parse4cn1] begin
        // Initialize and create installation as early as possible to increase the 
        // chance that the installation ID is already available the first time the app queries for it
        // (since saving the installation occurs asynchronously, we can't guarantee that it always 
        // happens before the CN1 app's start() method is invoked, where typically the installation
        // would be required). It's up to the CN1 app to decide how to respond if the ID is not yet ready
        // e.g. by polling.
        try
        {
            ParseClient.Initialize("11LTz32TfGPRMZh1SXohYYoGyTHKFumOitSyy1uw", "Az2yaaGEbOcbFbLxfRf9DcfYYHjMqDF81MYL52Q1");

            this.Startup += async (sender, args) => {
                // Track both regular and push app opens
                ParseAnalytics.TrackAppOpens(RootFrame);

                // Create and/or save an installation. A Parse installation identifies
                // an installation of your app on a given Windows Phone device.
                var installation = ParseInstallation.CurrentInstallation;
                await installation.SaveAsync();

                // Notify parse4cn1 of your installation. This is necessary since CN1 native code is not 
                // yet supported on Windows Phone so the app cannot request for the InstallationId when it needs it.
                com.parse4cn1.ParseInstallation.setInstallationId(global::com.codename1.impl.SilverlightImplementation.toJava(ParseInstallation.CurrentInstallation.InstallationId.ToString()));

                // Push won't work without deviceUris
                // This check was inspired by the official Parse sample project: 
                // https://github.com/ParsePlatform/PushTutorial/blob/master/WindowsPhone/ParsePhonePushSample/MainPage.xaml.cs
                if (!installation.ContainsKey("deviceUris"))
                {
                    String msg = "The ParseInstallation does not have a push channel. Make sure you have the ID_CAP_PUSH_NOTIFICATION capability";
                    com.parse4cn1.ParsePush.handlePushRegistrationStatus(global::com.codename1.impl.SilverlightImplementation.toJava(msg), 2);
                }
                else if (!installation.Get<IDictionary<string, object>>("deviceUris").ContainsKey("_Toast"))
                {
                    // Current, Parse only supports toast notifications so this is checked
                    String msg = "The device is not configured to receive toast notifications";
                    com.parse4cn1.ParsePush.handlePushRegistrationStatus(global::com.codename1.impl.SilverlightImplementation.toJava(msg), 2);
                }
                else
                {
                    // Report success if we're able to save the installation and it has the fields known to matter
                    // This might be a false positive but it's the best we can do since the Parse API doesn't seem to 
                    // provide a clear cut means to check push registration status.
                    com.parse4cn1.ParsePush.handlePushRegistrationStatus(null, 0);
                }
            };
        }
        catch (Exception ex)
        {
            // Failure to initialize installation is considered a push registration failure (may be a false negative)
            // Currently, the Parse API doc is silent on how to actually detect push registration failure.
            // This is the best bet for now.
            com.parse4cn1.ParsePush.handlePushRegistrationStatus(global::com.codename1.impl.SilverlightImplementation.toJava(ex.Message), 3);
        }
        // [parse4cn1] end

        InitializeComponent();
        InitializePhoneApplication();
        InitializeLanguage();
        if (Debugger.IsAttached)
        {
            Application.Current.Host.Settings.EnableFrameRateCounter = true;
            PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
        }
    }
    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
    }
    private void Application_Activated(object sender, ActivatedEventArgs e)
    {
    }
    private void Application_Deactivated(object sender, DeactivatedEventArgs e)
    {
    }
    private void Application_Closing(object sender, ClosingEventArgs e)
    {
    }
    private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
    {
        if (Debugger.IsAttached)
        {
            Debugger.Break();
        }
    }
    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
    {
        if (Debugger.IsAttached)
        {
            Debugger.Break();
        }
    }
    #region Phone application initialization
    private bool phoneApplicationInitialized = false;
    private void InitializePhoneApplication()
    {
        if (phoneApplicationInitialized)
            return;
        RootFrame = new PhoneApplicationFrame();
        RootFrame.Navigated += CompleteInitializePhoneApplication;
        RootFrame.NavigationFailed += RootFrame_NavigationFailed;
        RootFrame.Navigated += CheckForResetNavigation;
        phoneApplicationInitialized = true;
    }
    private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
    {
        if (RootVisual != RootFrame)
            RootVisual = RootFrame;
        RootFrame.Navigated -= CompleteInitializePhoneApplication;
    }
    private void CheckForResetNavigation(object sender, NavigationEventArgs e)
    {
        if (e.NavigationMode == NavigationMode.Reset)
            RootFrame.Navigated += ClearBackStackAfterReset;
    }
    private void ClearBackStackAfterReset(object sender, NavigationEventArgs e)
    {
        RootFrame.Navigated -= ClearBackStackAfterReset;
        if (e.NavigationMode != NavigationMode.New && e.NavigationMode != NavigationMode.Refresh)
            return;
        while (RootFrame.RemoveBackEntry() != null)
        {
            ;
        }
    }
    #endregion
    private void InitializeLanguage()
    {
        try
        {
            RootFrame.Language = XmlLanguage.GetLanguage(AppResources.ResourceLanguage);
            FlowDirection flow = (FlowDirection)Enum.Parse(typeof(FlowDirection), AppResources.ResourceFlowDirection);
            RootFrame.FlowDirection = flow;
        }
        catch
        {
            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }
            throw;
        }
    }
}

}

MainPage.xaml.cs

using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Navigation; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; using Main.Resources; using System.Windows.Shapes; using System.Windows.Media;

using Parse; using Newtonsoft.Json;

namespace Main { public partial class MainPage : PhoneApplicationPage { public static String BUILD_KEY = "dcd419e6-8be5-425b-838e-de03151a1bb7"; //public static String BUILD_KEY = "Az2yaaGEbOcbFbLxfRf9DcfYYHjMqDF81MYL52Q1";

    public static String PACKAGE_NAME = "br.com.liquidity.agenda.vilhena";
    public static String BUILT_BY_USER = "luiz04nl@gmail.com";
    public static String APP_NAME = "Main";
    public static String APP_VERSION = "1.0";
    private Main instance;

    // Constructor
    public MainPage()
    {
        // [parse4cn1] begin
        ParsePush.ParsePushNotificationReceived += (sender, args) => {
            // As far as I can tell from the documentation and tests, this only occcurs
            // when the app is in the foreground. 
            // See: https://msdn.microsoft.com/en-us/library/windows/apps/jj662938(v=vs.105).aspx 
            // and step 10 here https://msdn.microsoft.com/en-us/library/windows/apps/hh202967(v=vs.105).aspx
            // If the app is in the background or not running 
            // at all, a toast message is added to the status bar.
            // If the above does not hold, detecting app state and calling the proper handler should
            // also be quite straightforward.
            // For app lifecycle and event see: https://msdn.microsoft.com/en-us/library/windows/apps/ff817008(v=vs.105).aspx
            var strPayload = args.StringPayload;

            if (!com.parse4cn1.ParsePush.handlePushReceivedForeground(global::com.codename1.impl.SilverlightImplementation.toJava(strPayload)))
            {
                // When message is not handled, a reasonable 'do something' behavior is to show a message box
                // if the data has an alert (message to be shown) and/or title field (value to be displayed in notification)
                // see: https://parse.com/docs/dotnet/guide#push-notifications-sending-options
                var payload = args.Payload;
                object title;
                if (!payload.TryGetValue("title", out title))
                {
                    title = "Remote notification received";
                }
                object alert;
                if (!payload.TryGetValue("alert", out alert))
                {
                    alert = "";
                }
                MessageBox.Show(alert as string, title as string, MessageBoxButton.OK);
            }
        };
        // [parse4cn1] end

        InitializeComponent();
        Loaded += delegate {
            if (instance == null)
            {
                com.codename1.impl.SilverlightImplementation.setCanvas(this, LayoutRoot);
                com.codename1.ui.Display.init(null);
                com.codename1.ui.Display disp = (com.codename1.ui.Display)com.codename1.ui.Display.getInstance();
                disp.setProperty(global::com.codename1.impl.SilverlightImplementation.toJava("package_name"), global::com.codename1.impl.SilverlightImplementation.toJava(PACKAGE_NAME));
                disp.setProperty(global::com.codename1.impl.SilverlightImplementation.toJava("built_by_user"), global::com.codename1.impl.SilverlightImplementation.toJava(BUILT_BY_USER));
                disp.setProperty(global::com.codename1.impl.SilverlightImplementation.toJava("build_key"), global::com.codename1.impl.SilverlightImplementation.toJava(BUILD_KEY));
                disp.setProperty(global::com.codename1.impl.SilverlightImplementation.toJava("AppName"), global::com.codename1.impl.SilverlightImplementation.toJava(APP_NAME));
                disp.setProperty(global::com.codename1.impl.SilverlightImplementation.toJava("AppVersion"), global::com.codename1.impl.SilverlightImplementation.toJava(APP_VERSION));
                instance = new Main();
                instance.start();
                PhoneApplicationService.Current.Activated += Current_Activated;
                PhoneApplicationService.Current.Deactivated += Current_Deactivated;

                bool firstTime = com.codename1.io.Preferences.get(global::com.codename1.impl.SilverlightImplementation.toJava("cn1_first_time_req"), true);
                if (firstTime)
                {
                    com.codename1.io.Preferences.set(global::com.codename1.impl.SilverlightImplementation.toJava("cn1_first_time_req"), false);
                    Request r = new Request();
                    r.setPost(false);
                    r.setFailSilently(true);
                    r.setUrl(global::com.codename1.impl.SilverlightImplementation.toJava("https://codename-one.appspot.com/registerDeviceServlet"));
                    r.addArgument(global::com.codename1.impl.SilverlightImplementation.toJava("a"),
                        global::com.codename1.impl.SilverlightImplementation.toJava("parse4cn1TestApp"));
                    r.addArgument(global::com.codename1.impl.SilverlightImplementation.toJava("b"),
                        global::com.codename1.impl.SilverlightImplementation.toJava(BUILD_KEY));
                    r.addArgument(global::com.codename1.impl.SilverlightImplementation.toJava("by"),
                        global::com.codename1.impl.SilverlightImplementation.toJava(BUILT_BY_USER));
                    r.addArgument(global::com.codename1.impl.SilverlightImplementation.toJava("p"),
                        global::com.codename1.impl.SilverlightImplementation.toJava(PACKAGE_NAME));
                    java.lang.String ver = (java.lang.String)disp.getProperty(
                        com.codename1.impl.SilverlightImplementation.toJava("AppVersion"),
                        com.codename1.impl.SilverlightImplementation.toJava("1.0"));
                    r.addArgument(global::com.codename1.impl.SilverlightImplementation.toJava("v"), ver);
                    r.addArgument(global::com.codename1.impl.SilverlightImplementation.toJava("pl"), (java.lang.String)disp.getPlatformName());
                    r.addArgument(global::com.codename1.impl.SilverlightImplementation.toJava("u"), global::com.codename1.impl.SilverlightImplementation.toJava(""));
                    com.codename1.io.NetworkManager n = (com.codename1.io.NetworkManager)com.codename1.io.NetworkManager.getInstance();
                    n.addToQueue(r);
                }
            }
        };
    }

    void Current_Deactivated(object sender, DeactivatedEventArgs e)
    {
        instance.stop();
    }

    void Current_Activated(object sender, ActivatedEventArgs e)
    {
        if (!com.codename1.impl.SilverlightImplementation.exitLock)
        {
            instance.start();
        }
    }

    // [parse4cn1] begin
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        var jsonData = ParsePush.PushJson(e);
        if (jsonData != null && jsonData.Count != 0)
        {
            string jsonStr = JsonConvert.SerializeObject(jsonData);
            com.parse4cn1.ParsePush.handlePushOpen(global::com.codename1.impl.SilverlightImplementation.toJava(jsonStr),
                false /* From experiments, app is still transiting to the foreground so we don't consider it as being in foreground yet */);
        }
    }
    // [parse4cn1] end

    protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
        instance.stop();
    }
}
public class Request : com.codename1.io.ConnectionRequest
{
    public Request()
    {
        @this();
    }

    public override void readResponse(global::java.io.InputStream n1)
    {
        java.io.DataInputStream di = new java.io.DataInputStream();
        di.@this(n1);
        long l = di.readLong();
        com.codename1.io.Preferences.set(global::com.codename1.impl.SilverlightImplementation.toJava("DeviceId__$"), l);
    }
}

}

luiz04nl commented 8 years ago

Replacing the two files above the sample files, the app opens, but displays the following error:

capturar

luiz04nl commented 8 years ago

and what are all those numbers in right field?

FabricioCabeca commented 8 years ago

You should be able to track this error better in debug mode, you may have noticed the error dialog has a scroll, in debug mode you will also see the original windows exception before reaching the cn1 layer too, and you can use breakpoints to find the exact line.

You may also try enabling stuff in your init one by one until you find out where the error lies.

I do use many features and libs here but parse is not one of them, you may try disabling it too.

FabricioCabeca commented 8 years ago

btw, whatever is failing it seems like it is failing before loading the resource file (or maybe when loading the resource file itself, double check step 5 to be sure the res file is ok)

luiz04nl commented 8 years ago

thanks for the tips, most asked again, what are All Those numbers in right field? how to disable?

luiz04nl commented 8 years ago

could send me the link of some already published app to analyze a little?

FabricioCabeca commented 8 years ago

Those numbers are debug information, relax, these won't appear in a real device running without debug ;P

Example app: https://www.microsoft.com/en-us/store/apps/pumpop/9nblggh6gdgp

luiz04nl commented 8 years ago

tanks you

2016-02-10 15:05 GMT-02:00 FabricioCabeca notifications@github.com:

Those numbers are debug information, relax, these won't appear in a real device running without debug ;P

Example app: https://www.microsoft.com/en-us/store/apps/pumpop/9nblggh6gdgp

— Reply to this email directly or view it on GitHub https://github.com/Pmovil/CN1WindowsPort/issues/18#issuecomment-182483072 .

FabricioCabeca commented 8 years ago

De nada

FabricioCabeca commented 8 years ago

Also, check the extra-permissions step too

luiz04nl commented 8 years ago

not finalized yet the problem, bad already sure that the problem is in the .res file, but not have the slightest idea why, following the log

'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.CORE.NI.DLL'. Cannot find or open the PDB file. 'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\en-US\mscorlib.debug.resources.dll'. Module was built without symbols. Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.ni.dll 'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.COLLECTIONS.CONCURRENT.NI.DLL'. Cannot find or open the PDB file. 'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.REFLECTION.NI.DLL'. Cannot find or open the PDB file. 'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.THREADING.NI.DLL'. Cannot find or open the PDB file. 'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.RUNTIME.EXTENSIONS.NI.DLL'. Cannot find or open the PDB file. Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll 'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\System.Net.Requests.ni.DLL'. Cannot find or open the PDB file. 'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\System.Net.ni.DLL'. Cannot find or open the PDB file. 'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\System.Net.Primitives.ni.DLL'. Cannot find or open the PDB file. The thread 0xc40 has exited with code 0 (0x0). 'Main.exe' (CoreCLR: .): Loaded 'C:\windows\system32\SYSTEM.REFLECTION.EXTENSIONS.NI.DLL'. Cannot find or open the PDB file. Exception thrown: 'org.xmlvm._nExceptionAdapter' in Main.exe Stack traces aren't supported at the moment java.lang.IllegalArgumentException: The font file name must be relative to the root and end with ttf: native:MainBold Exception thrown: 'org.xmlvm._nExceptionAdapter' in Main.exe Stack traces aren't supported at the moment java.io.IOException: The font file name must be relative to the root and end with ttf: native:MainBold Exception thrown: 'System.NullReferenceException' in Main.exe Stack traces aren't supported at the moment java.lang.NullPointerException: System.NullReferenceException: Object reference not set to an instance of an object.

at generated.StateMachineBase.initTheme(Resources n1)

at generated.StateMachineBase.startApp(Resources n1, String n2, Boolean n3)

at generated.StateMachineBase.this(Resources n1, String n2, Boolean n3)

at generated.StateMachineBase.this(String n1)

at userclasses.StateMachine.this(String n1)

at br.com.liquidity.agenda.vilhena.MyApplication.start()

at Main.StartClass.run()

at com.codename1.ui.Display.processSerialCalls()

at com.codename1.ui.Display.mainEDTLoop() The thread 0xbec has exited with code 0 (0x0). The thread 0xc3c has exited with code 0 (0x0). The thread 0xcd0 has exited with code 0 (0x0). The thread 0xc54 has exited with code 0 (0x0).

PiotrZub commented 8 years ago

It is not easy task to prepare working project for CN1WindowsPort you must be an expert for native Windows app frameworks :( but it is possible :) I think in your case maybe this issue will be helpful: https://github.com/Pmovil/CN1WindowsPort/issues/1#issuecomment-149004628

luiz04nl commented 8 years ago

problem solved, thank you, definitely the problem was the .res file