Download Receiver / ScreenOn not working

I have an empty HelloWorld application:

package tutorials.TestReceivers;

import android.app.Activity;
import android.os.Bundle;

public class TestReceiversActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

With this BootReceiver.Java:

package tutorials.TestReceivers;

import android.content.BroadcastReceiver;

public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent arg1) {
    Intent intent = new Intent(context, TestReceiversActivity.class);
        context.startActivity(intent);    
    }
}

and this manifest:             

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TestReceiversActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver
            android-permission="android.permission.RECEIVE_BOOT_COMPLETED"
            android:name="development.TestReceiversActivity.BootReceiver" >
            <intent-filter >
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.SCREEN_ON" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

After starting the application and closing it.

When I unlock the screen (SCREEN_ON), ​​nothing worked.

And when I download the solution, I get the following msg as:

"The TestReceiversActivity application (process tutorials.TestReceivers) stops unexpectedly. Try again"

+5
source share
2 answers

After a long disappointment, I solved the problem above.

The correct way to register Boot Broadcast Receiver (and open activity according to it):

Empty HelloWorld application (TestReceiversActivity.java):

package tutorials.TestReceivers;

import android.app.Activity;
public class TestReceiversActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

(BootReceiver.java)

package tutorials.TestReceivers;

import android.content.BroadcastReceiver;
public class BootReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
         Log.d("DAVID", "Hi, Boot reciver was catch!");
         Intent i = new Intent(context, TestReceiversActivity.class);
         i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(i);
       }
}

. , !

:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="tutorials.TestReceivers"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">
            <receiver android:name=".BootReceiver" >
            <intent-filter >
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
        <activity android:name=".TestReceiversActivity"
                  android:label="@string/app_name">
                <intent-filter >
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
        </activity>
    </application>
 </manifest>

!

+7

android-permission="android.permission.RECEIVE_BOOT_COMPLETED". <uses-permission> <manifest>.

, adb logcat, DDMS DDMS Eclipse, LogCat , .

, , .

SCREEN_ON .

+4

All Articles