Thanks but It didn’t help. It seem that it was an error with the JNI code.
Now I’m getting this error:
03-06 15:38:08.941 15670 15691 W System.err: java.lang.NoSuchMethodError: no static method "Lcom/deeplink/DeepLinking;.getLinkedUrl()Ljava/lang/String"
03-06 15:38:08.941 15670 15691 W System.err: at org.haxe.lime.Lime.onRender(Native Method)
03-06 15:38:08.942 15670 15691 W System.err: at org.haxe.lime.MainView$Renderer.onDrawFrame(MainView.java:718)
03-06 15:38:08.942 15670 15691 W System.err: at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1571)
03-06 15:38:08.942 15670 15691 W System.err: at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)
03-06 15:38:08.942 15670 15691 I trace : DeepLinking.hx:25: deep linking error: JNI Exception
This is haxe code:
package;
#if cpp
import cpp.Lib;
#elseif neko
import neko.Lib;
#end
#if (android && openfl)
import openfl.utils.JNI;
#end
class DeepLinking {
#if android
public static var getLinkedUrl(default,null) : Void->String = function():String { return "nada"; }
public static function init()
{
try {
getLinkedUrl = JNI.createStaticMethod("com.deeplink.DeepLinking", "getLinkedUrl", "()Ljava/lang/String");
} catch(e:Dynamic) {
trace("deep linking error: "+e);
}
}
#end
}
and java code:
package com.deeplink;
import android.app.Activity;
import android.content.res.AssetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import org.haxe.extension.Extension;
public class DeepLinking extends Extension {
private static String urlLinked = "no link yet.";
/**
* Called after {@link #onCreate} — or after {@link #onRestart} when
* the activity had been stopped, but is now again being displayed to the
* user.
*/
public void onStart () {
// setContentView(R.layout.main);
// setContentView(Extension.mainActivity.getWindow().getAttributes())
// Intent intent = Extension.mainActivity.getIntent();
// String action = intent.getAction();
// // Uri data = intent.getData();
// urlLinked = intent.getDataString();
}
public static String getLinkedUrl () {
return urlLinked;
}
}
--------- beginning of crash
03-07 05:43:37.084 22328 22328 E AndroidRuntime: FATAL EXCEPTION: main
03-07 05:43:37.084 22328 22328 E AndroidRuntime: Process: com.tembac.bichitosMaker, PID: 22328
03-07 05:43:37.084 22328 22328 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.tembac.bichitosMaker/org.haxe.extension.deeplinking}: java.lang.ClassNotFoundException: Didn't find class "org.haxe.extension.deeplinking" on path: DexPathList[[zip file "/data/app/com.tembac.bichitosMaker-GaYCF_knD2vLWBdL-CFL-A==/base.apk"],nativeLibraryDirectories=[/data/app/com.tembac.bichitosMaker-GaYCF_knD2vLWBdL-CFL-A==/lib/arm, /system/fake-libs, /data/app/com.tembac.bichitosMaker-GaYCF_knD2vLWBdL-CFL-A==/base.apk!/lib/armeabi, /system/lib, /vendor/lib]]
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2679)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at android.app.ActivityThread.-wrap11(Unknown Source:0)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6494)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "org.haxe.extension.deeplinking" on path: DexPathList[[zip file "/data/app/com.tembac.bichitosMaker-GaYCF_knD2vLWBdL-CFL-A==/base.apk"],nativeLibraryDirectories=[/data/app/com.tembac.bichitosMaker-GaYCF_knD2vLWBdL-CFL-A==/lib/arm, /system/fake-libs, /data/app/com.tembac.bichitosMaker-GaYCF_knD2vLWBdL-CFL-A==/base.apk!/lib/armeabi, /system/lib, /vendor/lib]]
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
03-07 05:43:37.084 22328 22328 E AndroidRuntime: ... 9 more
03-07 05:43:37.089 790 2082 W ActivityManager: Force finishing activity com.tembac.bichitosMaker/org.haxe.extension.deeplinking
03-07 05:43:37.092 790 806 I ActivityManager: Showing crash dialog for package com.tembac.bichitosMaker u0
I think something is wrong with my java code but I’m sure what.
package org.haxe.extension;
import android.app.Activity;
import android.content.res.AssetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import org.haxe.extension.Extension;
import android.net.Uri;
public class DeepLinking extends Extension {
private static String urlLinked = "no link yet.";
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Extension.callbackHandler.post(new Runnable() {
@Override public void run() {
//setContentView(Extension.mainView);
// Get the intent set on this activity
Intent intent = Extension.mainActivity.getIntent();
// Get the uri from the intent
Uri uri = intent.getData();
// Do not continue if the uri does not exist
if (uri == null) {
return;
}
final String dataString = intent.getDataString();
if(dataString == null)
{
urlLinked = dataString;
}
}
});
}
public static String linkedUrl () {
return urlLinked;
}
}
Maybe I’m confused but I think this can’t be done with extensions.
As the manifest says, I need an activity when a link is pressed to handle it. But the Extension is not an activity so Android cannot find the activity to handle the incoming link.
I need some way to reference the main activity from the extension Manifest.
Try capitalizing it, to match the declaration. I forget if it wants a fully-qualified package name, but in case it does, try “::APP_PACKAGE::.MainActivity”.
I’m pretty sure that means you are creating your own separate activity.
But now that I look at it, I think Joshua was on to something. Why is it looking for a class named deeplinking rather than DeepLinking? I don’t see either of those in your manifest file, so… are you sending a deep link that has a lowercase class name?
That was a mistake I had before but I fixed it and it is still crashing when I open a link using the app. Since my last post I changed the package of the extension but it still crashing.
The extension crashes when I try to open a link with the app. It works fine when is executed.
Error:
--------- beginning of crash
03-07 17:47:27.788 20975 20975 E AndroidRuntime: FATAL EXCEPTION: main
03-07 17:47:27.788 20975 20975 E AndroidRuntime: Process: com.example.myapp, PID: 20975
03-07 17:47:27.788 20975 20975 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.myapp/com.deeplink.LinkActivity}: java.lang.ClassCastException: com.deeplink.LinkActivity cannot be cast to android.app.Activity
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2488)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:111)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at android.os.Looper.loop(Looper.java:207)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5765)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: Caused by: java.lang.ClassCastException: com.deeplink.LinkActivity cannot be cast to android.app.Activity
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at android.app.Instrumentation.newActivity(Instrumentation.java:1072)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2478)
03-07 17:47:27.788 20975 20975 E AndroidRuntime: ... 9 more
package com.deeplink;
import android.app.Activity;
import android.content.res.AssetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import org.haxe.extension.Extension;
import android.net.Uri;
public class LinkActivity extends Extension{
private static String urlLinked = "no link yet.";
//public void onCreate(Bundle savedInstanceState) {
//super.onCreate(savedInstanceState);
//
// // Extension.callbackHandler.post(new Runnable() {
// // @Override public void run() {
// setContentView(Extension.mainView);
//
// // Get the intent set on this activity
// Intent intent = getIntent();
//
// // Get the uri from the intent
// Uri uri = intent.getData();
//
// // Do not continue if the uri does not exist
// if (uri == null) {
// return;
// }
//
// final String dataString = intent.getDataString();
// if(dataString == null)
// {
// urlLinked = dataString;
// }
// }
// });
//}
public static String linkedUrl () {
return urlLinked;
}
}
Haxe
package;
#if (android && openfl)
import openfl.utils.JNI;
#end
class DeepLinking {
public static function getLink ():String {
#if (android && openfl)
var resultJNI = testextension_linkedUrl_jni();
return resultJNI;
#else
return "plataforma no soporta deep links.";
#end
}
#if (android && openfl)
private static var testextension_linkedUrl_jni = JNI.createStaticMethod("com.deeplink.LinkActivity", "linkedUrl", "()Ljava/lang/String;");
#end
}
Include:
<?xml version="1.0" encoding="utf-8"?>
<project>
<!-- Use the following for an Android Java extension, not needed otherwise -->
<dependency name="LinkActivity" path="dependencies/android" if="android" />
<android extension="com.deeplink.LinkActivity" />
</project>
--------- beginning of crash
03-07 22:51:21.757 2019 2019 E AndroidRuntime: FATAL EXCEPTION: main
03-07 22:51:21.757 2019 2019 E AndroidRuntime: Process: com.example.myapp, PID: 2019
03-07 22:51:21.757 2019 2019 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.deeplink.LinkActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2583)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2665)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1499)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:111)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.os.Looper.loop(Looper.java:207)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5765)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.view.ViewGroup.addViewInner(ViewGroup.java:4438)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.view.ViewGroup.addView(ViewGroup.java:4274)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.view.ViewGroup.addView(ViewGroup.java:4246)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:442)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:423)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.app.Activity.setContentView(Activity.java:2211)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at com.deeplink.LinkActivity.onCreate(LinkActivity.java:24)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6317)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2530)
03-07 22:51:21.757 2019 2019 E AndroidRuntime: ... 9 more
I looked up Google’s tutorial, and there’s a significant difference between their code and yours: they don’t have the line “setContentView(Extension.mainView).” (Nor do they have anything similar.)
And that’s the line that’s causing your error. Why not try deleting it?
I maintain that you don’t need that line. Not in a class that extends Extension, at least. Lime handles that, and you shouldn’t need to do it again.
Try commenting out lines to pinpoint what’s causing the black screen. It can’t be the lack of setContentView(), because Extension.onCreate() lacks that too, and that didn’t cause any issues.
Sorry that I took so long to get back to this. I did a workaround for the GDC build for this feature but now I will need to implement it. I’m really close.
The game is recognizing the link and it opens the app when clicked. But it stays on this activity that is blank. If I open the game again, it read the text from the link fine.
So what I need to do is to open and show the GameActivity from my LinkActivity. I’m looking for solutions with no luck so far. I hope someone with more native knowledge can help.
The link activity code is:
package com.deeplink;
import android.app.Activity;
import android.content.res.AssetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import org.haxe.extension.Extension;
import android.net.Uri;
import android.util.Log;
public class LinkActivity extends Activity{
private static String urlLinked = "no link yet.";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the intent set on this activity
Intent intent = getIntent();
// Get the uri from the intent
Uri uri = intent.getData();
// Do not continue if the uri does not exist
if (uri == null) {
return;
}
final String dataString = intent.getDataString();
if(dataString != null)
{
urlLinked = dataString;
}
Log.d("FuncaLink", "link: " + urlLinked);
}
public static String linkedUrl () {
return urlLinked;
}
}
I’m triying to start the new activity like this but it can’t find the main activity package.
package com.deeplink;
import android.app.Activity;
import android.content.res.AssetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import org.haxe.extension.Extension;
import ::APP_PACKAGE::.MainActivity;
import android.net.Uri;
import android.util.Log;
public class LinkActivity extends Activity{
private static String urlLinked = "no link yet.";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the intent set on this activity
Intent intent = getIntent();
// Get the uri from the intent
Uri uri = intent.getData();
// Do not continue if the uri does not exist
if (uri == null) {
return;
}
final String dataString = intent.getDataString();
if(dataString != null)
{
urlLinked = dataString;
}
Log.d("FuncaLink", "link: " + urlLinked);
//intenta ejecutar la actividad del juego
Intent intentNewActivity = new Intent(Extension.mainContext, MainActivity.class);
startActivity(intentNewActivity);
}
public static String linkedUrl () {
return urlLinked;
}
}