Flutter add activity to Android Manifest for ImageCropper - android

I am trying to implement ImageCropper inside my app. On Android I need to add some things to the Manifest according to the documentation but I can not make it work... This is my Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.memories">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<application>
<activity>
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
But this crashes with this error:
E/AndroidRuntime( 9936): at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime( 9936): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime( 9936): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9936): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime( 9936): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime( 9936): Caused by: java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime( 9936): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:155)
E/AndroidRuntime( 9936): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:238)
E/AndroidRuntime( 9936): at vn.hunghd.flutter.plugins.imagecropper.ImageCropperDelegate.onActivityResult(ImageCropperDelegate.java:106)
E/AndroidRuntime( 9936): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEngineConnectionRegistry.java:739)
E/AndroidRuntime( 9936): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult(FlutterEngineConnectionRegistry.java:426)
E/AndroidRuntime( 9936): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:677)
E/AndroidRuntime( 9936): at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:624)
E/AndroidRuntime( 9936): at android.app.Activity.dispatchActivityResult(Activity.java:8310)
E/AndroidRuntime( 9936): at android.app.ActivityThread.deliverResults(ActivityThread.java:5008)
E/AndroidRuntime( 9936): ... 11 more
I/Process ( 9936): Sending signal. PID: 9936 SIG: 9
What am I missing here? What is the correct way to add the activities?

Try this code in you AndroidMainfest. May be you are missing Launcher Activity in application level.
<application
android:name="io.flutter.app.FlutterApplication"
android:label="example"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"/>
</application>

aaah... I changed the wrong manifest... it is important to change the main:
/android/app/src/main/AndroidManifest.xml
Everything is working fine now.

Related

Class not found exception on firebase messaging flutter

I keep getting classNotFoundException when sending cloud notifications from firebase. The error logs that it can not find .java.MyFirebaseMessagingService I have followed everything as per the documentation but still can not find the fix.
Here's the error log. The app opens fine and only crashes when I send a message from the firebase console to test.
java.lang.RuntimeException: Unable to instantiate service com.myapp.MyApp.MyFirebaseMessagingService: java.lang.ClassNotFoundException: Didn't find class "com.myapp.MyApp.MyFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/lib/arm64, /data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
E/AndroidRuntime( 5956): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3577)
E/AndroidRuntime( 5956): at android.app.ActivityThread.-wrap4(Unknown Source:0)
E/AndroidRuntime( 5956): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1862)
E/AndroidRuntime( 5956): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 5956): at android.os.Looper.loop(Looper.java:198)
E/AndroidRuntime( 5956): at android.app.ActivityThread.main(ActivityThread.java:7055)
E/AndroidRuntime( 5956): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5956): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:523)
E/AndroidRuntime( 5956): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:836)
E/AndroidRuntime( 5956): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.MyAppMyFirebaseMessagingService" on path: DexPathList[[zip file "/data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/lib/arm64, /data/app/com.myapp.MyApp-2_H2R81paYjm5b8ZDse8Uw==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
E/AndroidRuntime( 5956): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
E/AndroidRuntime( 5956): at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime( 5956): at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime( 5956): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3574)
E/AndroidRuntime( 5956): ... 8 more
And the manifest file is.
<application
android:name=".Application"
android:label="MyApp"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:showWhenLocked="true"
android:turnScreenOn="true"
android:windowSoftInputMode="adjustResize">
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="#style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="#drawable/launch_background"
/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_logo" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name=".service.MyFirebaseMessagingService"
>
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
I know that the question is answered but recently I too got stuck in the same issue and your comment saved me. Thanks! I want to increase the visibility of your answer for others.
To resolve this issue. I just removed this code segment and the application started working as intended:
<service
android:name=".service.MyFirebaseMessagingService"
>
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
I think there is no need to explicitly declare class .service.MyFirebaseMessagingService as you don't need to mention it for the projects.
Follow all the instructions provided in the firebase_messaging | Flutter Package. You may get one error error: incompatible types: PluginRegistry cannot be converted to FlutterEngine GeneratedPluginRegistrant.register with (registry); while following the instruction. To solve this error, follow the instructions provided in this thread: PluginRegistry cannot be converted to FlutterEngine
and you won't face any issues.
If you want to listen for messages on Background / Foreground , You don't need :
<service android:name=".service.MyFirebaseMessagingService">
The Flutter Package gives to you other tools to make this happen.
If you want to use Flutter for listening to Firebase PushNotifications (and not the native way), try to use the FirebaseMessaging.onMessage.listen( ... ) dart function.
And remember, for android:
If the application is currently in the foreground, the visible notification is not presented by default (but you can make it happen).
You can check how to use the notification handling in the Firebase flutter documentation:
https://firebase.flutter.dev/docs/messaging/notifications/
✌️

Xamarin NPE on Confirmation Activity on Wear

I'm developing a Wear application and wanted to show a Confirmation message to the user after a click.
I know that for Wear dedicated tools like ConfirmationActivity exist, but after trying to show it I receive a Null Pointer Exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageDrawable(android.graphics.drawable.Drawable)' on a null object reference
This is the offending code causing the NPE:
Intent intent = new Intent(ApplicationContext, typeof(ConfirmationActivity));
intent.PutExtra(ConfirmationActivity.ExtraAnimationType, ConfirmationActivity.SuccessAnimation);
StartActivity(intent);
Here's the application manifest (notice I declared ConfirmationActivity):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="xx.xxxxxxx.xxxxxxx" android:installLocation="auto">
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="28" />
<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:supportsRtl="true" android:theme="#android:style/Theme.DeviceDefault">
<uses-library android:name="com.google.android.wearable" android:required="true" />
<!--
Set to true if your app is Standalone, that is, it does not require the handheld
app to run.
-->
<meta-data android:name="com.google.android.wearable.standalone" android:value="true" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<receiver android:name=".BootReceiver" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity android:name="android.support.wearable.activity.ConfirmationActivity"></activity>
</application>
</manifest>
This is the stack trace:
07-02 07:41:50.270 E/AndroidRuntime( 6760): java.lang.RuntimeException: Unable to start activity ComponentInfo{xx.xxxxxxxx.xxxxxx/android.support.wearable.activity.ConfirmationActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageDrawable(android.graphics.drawable.Drawable)' on a null object reference
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.-wrap11(Unknown Source:0)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.os.Handler.dispatchMessage(Handler.java:105)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.os.Looper.loop(Looper.java:164)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.main(ActivityThread.java:6541)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at java.lang.reflect.Method.invoke(Native Method)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
07-02 07:41:50.270 E/AndroidRuntime( 6760): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageDrawable(android.graphics.drawable.Drawable)' on a null object reference
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.support.wearable.view.ConfirmationOverlay.updateImageView(ConfirmationOverlay.java:302)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.support.wearable.view.ConfirmationOverlay.updateOverlayView(ConfirmationOverlay.java:249)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.support.wearable.view.ConfirmationOverlay.showOn(ConfirmationOverlay.java:194)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.support.wearable.activity.ConfirmationActivity.onCreate(ConfirmationActivity.java:79)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.Activity.performCreate(Activity.java:6975)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
I think your context is incorrect. Try this:
Intent intent = new Intent (this, typeof(ConfirmationActivity))
.SetFlags (ActivityFlags.NewTask | ActivityFlags.NoAnimation)
.PutExtra (ConfirmationActivity.ExtraAnimationType, ConfirmationActivity.SuccessAnimation)
.PutExtra (ConfirmationActivity.ExtraMessage, "Message Goes Here");
StartActivity (intent);
And if that doesn't work either, you might have to override the Intent handling function too, as you can see here and here.

Unable to find explicit activity (Kotlin)

i made a new activity and when i im trying to move between them by clicking a button the app crash and logcat shows the error below
12-16 14:02:09.016 23235-23235/com.modather.scalculate E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.modather.scalculate, PID: 23235
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.modather.scalculate/android.support.v7.widget.AppCompatButton}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java)
at android.app.Instrumentation.execStartActivity(Instrumentation.java)
at android.app.Activity.startActivityForResult(Activity.java)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67)
at android.app.Activity.startActivityForResult(Activity.java)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720)
at android.app.Activity.startActivity(Activity.java)
at android.app.Activity.startActivity(Activity.java)
at com.modather.scalculate.HomePage$onCreate$1.onClick(HomePage.kt:36)
at android.view.View.performClick(View.java)
at android.view.View$PerformClick.run(View.java)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:107)
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".HomePage"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.modather.scalculate.age"
android:label="Calculate my age(SC)" />
</application>
i had searched over stackoverflow and found some solution but it didn't work for me.. so if it possible to fix mine ?
Here's the moving code
fab.setOnClickListener {
val intent = Intent(this, activity_age::class.java)
startActivity(intent)
}
There is Typing mistake check it
your activity name is activity_age and you have added in manifest age is
fab.setOnClickListener {
val intent = Intent(this,age::class.java)
startActivity(intent)
}

App Keeps Force Closing with Google Cloud Messaging on Android

I'm in the process of making my own Android app and along the way discovered GCM (Google Cloud Messaging). I followed the following tutorial exactly: http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/
The good news is that almost everything works properly, except that every time I send a push notification, the App force closes on the device. I don't think anything is wrong with the Eclipse project and I'm running Android 4.2.2 on my device. There are no compilation errors. It is driving me nuts that I can't figure out why the App keeps force closing.
The code is exactly the same as what is listed in the above link. For reference, here is my logcat:
E/AndroidRuntime( 7261): FATAL EXCEPTION: main
E/AndroidRuntime( 7261): java.lang.RuntimeException: Unable to instantiate receiver com.javapapers.android.GcmBroadcastReceiver: java.lang.ClassNotFoundException: Didn't find class "com.javapapers.android.GcmBroadcastReceiver" on path: /data/app/com.javapapers.android-1.apk
E/AndroidRuntime( 7261): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2428)
E/AndroidRuntime( 7261): at android.app.ActivityThread.access$1600(ActivityThread.java:151)
E/AndroidRuntime( 7261): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1358)
E/AndroidRuntime( 7261): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 7261): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 7261): at android.app.ActivityThread.main(ActivityThread.java:5285)
E/AndroidRuntime( 7261): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 7261): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 7261): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
E/AndroidRuntime( 7261): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
E/AndroidRuntime( 7261): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
E/AndroidRuntime( 7261): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 7261): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.javapapers.android.GcmBroadcastReceiver" on path: /data/app/com.javapapers.android-1.apk
E/AndroidRuntime( 7261): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
E/AndroidRuntime( 7261): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime( 7261): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime( 7261): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2423)
E/AndroidRuntime( 7261): ... 11 more
W/GTalkService( 1430): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.javapapers.android (has extras) }
My manifest looks like the following:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.javapapers.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.javapapers.android.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="16" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".RegisterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.javapapers.android.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" >
</activity>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.javapapers.android" />
</intent-filter>
</receiver>
<service android:name=".GCMNotificationIntentService" />
I'm at my wits end trying to figure out what is wrong, so any and all help is appreciated.
What package is your GcmBroadcastReceiver located in?
When using the . prefix, like you did when declaring .GcmBroadcastReceiver, the . translates to your package name. So unless GcmBroadcastReceiver is located in com.javapapers.android then it will not work.
Even I faced same concern. Right Click project go to -> build Path -> Config Build path -> order and export -> check mark Android dependencies (google paly services.jar) shift to top. Now Clean and build and run your application.

Class for an Activity set up in the AndroidManifest cannot be found

I defined following activity and intent filter in AndroidManifest.xml:
<application android:label="Test.SampleApp">
<activity android:name=".MainActivity"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Then I have an Activity set up as:
namespace Test.SampleApp
{
public class MainActivity : Activity
{
//....
}
}
The problem is that when I start the application, it cannot find the MainActivity class:
E/AndroidRuntime( 2047): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{Test.SampleApp/Test.SampleApp.MainActivity}: java.lang.ClassNotFoundException: Test.SampleApp.MainActivity
E/AndroidRuntime( 2047): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
E/AndroidRuntime( 2047): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime( 2047): at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime( 2047): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime( 2047): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2047): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 2047): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 2047): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2047): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 2047): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 2047): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 2047): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2047): Caused by: java.lang.ClassNotFoundException: Test.SampleApp.MainActivity
E/AndroidRuntime( 2047): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime( 2047): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime( 2047): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime( 2047): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
E/AndroidRuntime( 2047): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
E/AndroidRuntime( 2047): ... 11 more
W/ActivityManager( 162): Force finishing activity Test.SampleApp/.MainActivity
I'm guessing that I'm not referring to the Activity correctly in the manifest?
I've also tried using the 'Test.SampleApp.MainActivity' as a vlue for android:name,
but then the manifest is simply invalid and cannot be parsed.
I'm using Mono for Android, and now I'm wondering, the names used in the manifest,
do they relate to the C# namespaces or to something elsethat is specific to the Android platform?
Note: In the manifest I've also have package="Test.SampleApp"
Update: I added the "." in front of MainActivity but I'm still getting the exact same exception.
Based on the feedback (link) from #Triode I managed to figure it out:
The manifest in the sample application on github:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="mono.actionbarsherlocktest">
<uses-sdk android:minSdkVersion="7" />
<application android:label="Mono.ActionbarsherlockTest">
</application>
</manifest>
The package name here is lower case whereas my package name contained capitals.
Changing the package name to test.sampleapp and leaving everything else untouched solved the issue.
I hope this will help other monodroid users one day.
In general, do not write XML fragments for C#-provided activities. Instead, use custom attributes and let the build system worry about it for you.
namespace NamespaceName {
[Activity(
LaunchMode=Android.Content.PM.LaunchMode.SingleInstance,
StateNotNeeded=true)]
[IntentFilter (new[]{Android.Content.Intent.ActionMain},
Categories=new[]{Android.Content.Intent.CategoryHome, Android.Content.Intent.CategoryDefault})]
public class MainActivity : Activity {
// ...
}
}
The build system will generate the <activity/> element and use fully-qualified type names:
<activity android:name="namespacename.MainActivity"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
There are typically only two reasons to use XML fragments and not custom attributes:
The type doesn't exist in C#, e.g. your .apk contains Java activities.
You need to use XML attributes/elements that haven't been exposed via custom attributes.

Categories

Resources