Amit
Amit

Reputation: 264

Receiving data from another app in xamarin,android

I had made an app using xamarin.android that plays with images. I want other app to share images to my app, I tried the following but throws exception.

Here is Android manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
          package="ReceiveDataFromApp.ReceiveDataFromApp" 
          android:versionCode="1" 
          android:versionName="1.0">
  <uses-sdk android:minSdkVersion="21" />
  <application android:allowBackup="true" android:label="@string/app_name">
    <activity
       android:name=".MainActivity"
       android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
      </intent-filter>
    </activity>
  </application>
</manifest>

Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/imageView"
       />
</LinearLayout>

MainActivity.cs

namespace ReceiveDataFromApp
{
    [Activity(Label = "ReceiveDataFromApp", MainLauncher = true)]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);`

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            ImageView imageView = (ImageView)FindViewById(Resource.Id.imageView);

            if (Intent.Data != null)
            {
                try
                {
                    var uri = Intent.Data;
                    var iis = ContentResolver.OpenInputStream(uri);
                    imageView.SetImageBitmap(BitmapFactory.DecodeStream(iis));
                }
                catch (Exception e)
                {
                    Toast.MakeText(this, e.Message, ToastLength.Long).Show();
                }
            }
        }
    }
}

Exception:

Java.Lang.RuntimeException: Unable to instantiate activity ComponentInfo{ReceiveDataFromApp.ReceiveDataFromApp/ReceiveDataFromApp.ReceiveDataFromApp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "ReceiveDataFromApp.ReceiveDataFromApp.MainActivity" on path: DexPathList[[zip file "/data/app/ReceiveDataFromApp.ReceiveDataFromApp-1/base.apk"],nativeLibraryDirectories=[/data/app/ReceiveDataFromApp.ReceiveDataFromApp-1/lib/arm, /data/app/ReceiveDataFromApp.ReceiveDataFromApp-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]

Do correct what I am doing wrong.

Upvotes: 2

Views: 1858

Answers (3)

Amit
Amit

Reputation: 264

Here's the solution of the issue, thanks to @sushihangover

[Activity(Name = "ReceiveDataFromApp.ReceiveDataFromApp.MainActivty", Label = "ReceiveDataFromApp", MainLauncher = true)]
public class MainActivity : Activity
~~~~

In manifest file you have to add:

<activity    
   android :name="ReceiveDataFromApp.ReceiveDataFromApp.MainActivity"
   android:label="@string/app_name">

Upvotes: 2

SushiHangover
SushiHangover

Reputation: 74124

ClassNotFoundException: Didn't find class "ReceiveDataFromApp.ReceiveDataFromApp.MainActivity"

By default, Xamarin creates MD5-based Java class names to avoid name clashing in the generated Java wrappers.

To hard-code a Java class name, use the Name parameter in the ActivityAttribute

[Activity(Name = "ReceiveDataFromApp.ReceiveDataFromApp.MainActivty", Label = "ReceiveDataFromApp", MainLauncher = true)]
public class MainActivity : Activity
~~~~

Upvotes: 3

DimDim
DimDim

Reputation: 381

The Android operating system uses content providers to facilitate access to shared data such as images, media files, contacts and so on. You can find how to use it here.

Upvotes: 0

Related Questions