好的,我在这里有一个奇怪的错误,我无法弄清楚。我在android" android.intent.action.SEND"中与共享选项列表共享数据。
分享单张图片效果很好,但是当我尝试分享纯文本,例如" asdfdgdsfsa"时,该程序会抛出此错误
" Java.Lang.RuntimeException:无法实例化活动 ComponentInfo {com.companyname.Revamp / Revamp.RecieveDataFromApp.RecieveDataFromApp}: java.lang.ClassNotFoundException:没找到类 " Revamp.RecieveDataFromApp.RecieveDataFromApp"在路径上: DexPathList [[zip文件 " /data/app/com.companyname.Revamp-HFm6SmD1Y-A76OQwcwCXIA == / base.apk&#34],nativeLibraryDirectories = [/数据/应用/ com.companyname.Revamp-HFm6SmD1Y-A76OQwcwCXIA == / lib中/ 86, /系统/假库, /data/app/com.companyname.Revamp-HFm6SmD1Y-A76OQwcwCXIA==/base.apk!/lib/x86, / system / lib,/ vendor / lib]]"。
protected override void OnCreate(Bundle bundle)
{
Intent intent = Intent;
String action = Intent.Action;
String type = intent.Type;
if (Intent.ActionSend.Equals(action) && type != null)
{
// This is what we are trying to get working here.
if ("text/plain".Equals(type))
{
// Handle text being sent
// ...
// ...
// ...
}
else if (type.StartsWith("image/"))
{
// Handle single image being sent
// ...
// ...
// ...
}
}
else if (Intent.ActionSendMultiple.Equals(action) && type != null)
{
//This works
if (type.StartsWith("image/"))
{
// Handle multiple images being sent
// ...
// ...
// ...
}
}
else
{
// Handle other intents, such as being started from the home screen
}
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
<activity android:name="Revamp.RecieveDataFromApp.RecieveDataFromApp" android:icon="@drawable/ic_home">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</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>
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
答案 0 :(得分:0)
我已经测试了您的代码并重现了该问题。您可以尝试在代码中设置intent-filter
,而不是AndroidManifest.xml
例如:
[Activity(Label = "RecieveDataFromApp", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "image/*", Label = "RecieveDataFromApp")]
[IntentFilter(new[] { Intent.ActionSend }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "text/plain", Label = "RecieveDataFromApp")]
[IntentFilter(new[] { Intent.ActionSendMultiple }, Categories = new[] { Intent.CategoryDefault }, DataMimeType = "image/*", Label = "RecieveDataFromApp")]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
...
...
...
}