-2

i'm just practing and i'm trying to make simple brodcastreceiver in Android Studio.

I have this manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.maurelio.flipcover">

<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">

    <receiver android:name="SensorReceiver">

        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED">
            </action>
        </intent-filter>

    </receiver>

</application>

and i have this SensorReceiver.java

package org.maurelio.flipcover;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

/**
 * Created by maurelio on 22/03/18.
*/

public class SensorReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, "Intent Detected.", 
    Toast.LENGTH_LONG).show();
  }
}

When i try to run the app i get: "Default Activity not found". I tried also invalidate chache/restart, nothing change.

What i'm doing wrong?

Thanks and regards.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
maurelio79
  • 292
  • 1
  • 9
  • Duplicate https://stackoverflow.com/questions/15825081/error-default-activity-not-found – ADM Mar 22 '18 at 18:33
  • 1
    i cant see your activity in Manifest !! he is trying to run an app without an activity @ADM :D – Santanu Sur Mar 22 '18 at 18:37
  • Possible duplicate of [Android - Start service on boot](https://stackoverflow.com/questions/7690350/android-start-service-on-boot) – Santanu Sur Mar 22 '18 at 18:44
  • You dont have any activity in application. Your application contain only receiver. When you run app system will try to find default activity as entry point of app. – Vishu Mar 22 '18 at 18:48
  • Sorry to all, but reading this: https://developer.android.com/guide/components/broadcasts.html i was thinking that if i set a receiver in the manifest that is the default activity, also reading here https://www.tutorialspoint.com/android/android_broadcast_receivers.htm Where is MainActivity in manifest of second link? – maurelio79 Mar 22 '18 at 19:04
  • An "activity" is specifically an `Activity` subclass. Since Android 3.1, you need to have at least one to allow the user to launch your app after installation. Until then, your app is in the _stopped_ state, and the Receiver you have registered in the manifest won't work. – Mike M. Mar 22 '18 at 22:42

2 Answers2

0

This is because you do not have a default activity defined in your manifest.xml file.

Normally you would have a MainActivity defined there.

In the tutorial you used, there is no MainActivity in their manifest, but I think that is their mistake. However, they do describe the MainActivity class itself.

I would suggest using Android Studio to create a new project from a blank template such as "Basic Activity" and then slowly adding your code to that new project.

Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
0

Create an empty activity in your current project and add the below part to your manifest

 <activity android:name=".YourActivityName">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

change the activity name with your new activity

MarGin
  • 2,078
  • 1
  • 17
  • 28