Hoping for help as I am desperately trying to get this to work since two days.
My goal is to receive text and images in my Adobe AIR app via the "Share" popup on Android.
Yes, I am aware of the documented solution with the InvokeEvent that is supposed to work but it doesn't work with android.intent.action.SEND - the InvokeEvents are dispatched in the app but all arguments are always empty. If someone knows about a solution there please let me know.
So I have tried to implement an ANE to catch up these intents and pass them into my app. First, here is my setup:
AIR and ANE (Android) app descriptors look the same - inside of the manifest part I have this:
<application android:enabled="true">
<activity>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.mypackage.androidsendintent.SendIntentActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
</application>
My Activity JAVA file:
package com.mypackage.androidsendintent;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
public class SendIntentActivity extends Activity
{
public static final String TAG = "SendIntentActivity";
private AndroidSendIntentContext sendIntentContext = AndroidSendIntentContext.getInstance();
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Get intent, action and MIME type
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
Log.d(TAG, "ACTIVITY");
if (Intent.ACTION_SEND.equals(action) && type != null)
{
if ("text/plain".equals(type))
{
handleSendText(intent); // Handle text being sent
}
else if (type.startsWith("image/"))
{
handleSendImage(intent); // Handle single image being sent
}
}
else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null)
{
if (type.startsWith("image/"))
{
handleSendMultipleImages(intent); // Handle multiple images being sent
}
}
else
{
// Handle other intents, such as being started from the home screen
}
}
void handleSendText(Intent intent)
{
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null)
{
// Update UI to reflect text being shared
Log.d(TAG, "handleSendText " + sharedText);
sendIntentContext.dispatchStatusEventAsync("SHARED_TEXT", sharedText);
}
}
void handleSendImage(Intent intent)
{
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null)
{
// Update UI to reflect image being shared
Log.d(TAG, "handleSendImage " + imageUri);
sendIntentContext.dispatchStatusEventAsync("SHARED_IMAGES", imageUri.toString());
}
}
void handleSendMultipleImages(Intent intent)
{
ArrayList<Uri> imageUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (imageUris != null)
{
// Update UI to reflect multiple images being shared
Log.d(TAG, "handleSendMultipleImages " + imageUris);
String listString = "";
for (Uri myUri : imageUris)
{
if(listString != "")
listString += ",";
listString += myUri.toString();
}
sendIntentContext.dispatchStatusEventAsync("SHARED_IMAGES", listString);
}
}
}
It is quite working but there are two problems:
1. When i share something another (blank) screen is coming up with the name of my app but the app (that is running in background) still receiving the data, so basically I need to switch to my app to see the shared content. This sounds like something small I'm missing?
2. When the app is NOT already running in the background I'm getting an exception:
FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Native method not found: com.adobe.fre.FREContext.dispatchStatusEventAsync:(Ljava/lang/String;Ljava/lang/String;)V
at com.adobe.fre.FREContext.dispatchStatusEventAsync(Native Method)
at com.mypackage.androidsendintent.SendIntentActivity.handleSendText(SendIntentActivity.java :61)
at com.mypackage.androidsendintent.SendIntentActivity.onCreate(SendIntentActivity.java:33)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
Looks like there is some problem with the FreContent ?
I would appreciate any help, getting desperate here. Thank you for your time !