Android的引导进行广播不调用 [英] Android Boot-Up BroadCast Not invoking

查看:106
本文介绍了Android的引导进行广播不调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在做广播接收器Android设备启动后,将调用,然后将运行一个后台服务。我已经尝试了很多例子,但不知道我要去哪里错了。我下面这个例子: https://github.com/commonsguy/cw-advandroid/tree/master / SystemEvents / ONBOOT 我已导入这整个项目在我的工作区,并试图逃跑。但是接收器未援引左右。 请帮助我。 我的测试设备为:Motorolla的Xoom与ICS 4.0.3

I am currently trying to make a broadcast receiver which will invoke after android device boots and then will run a background service. I have tried many examples but don't know where I'm going wrong. I am following this example: https://github.com/commonsguy/cw-advandroid/tree/master/SystemEvents/OnBoot I have imported this whole project in my workspace and tried to run. But the receiver didn't invoked or so. Please help me out. My Testing Device is: Motorolla Xoom with ICS 4.0.3

修改

清单

<uses-sdk android:minSdkVersion="8" />

<supports-screens
    android:anyDensity="true"
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true" />

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.REBOOT" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <service
        android:name="awais.soft.MyService"
        android:enabled="true" >
        <intent-filter>
            <action android:name="awais.soft.MyService" >
            </action>
        </intent-filter>
    </service>

    <receiver android:name="awais.soft.ServicesDemoActivity" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" >
            </action>

            <category android:name="android.intent.category.HOME" >
            </category>
        </intent-filter>
    </receiver>
</application>

广播接收器

package awais.soft;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;

public class ServicesDemoActivity extends BroadcastReceiver {

static final int idBut = Menu.FIRST + 1, idIntentID = Menu.FIRST + 2;

@Override
public void onReceive(Context context, Intent intent) {

    Log.e("Awais", "onReceive:");
    if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
        Intent i = new Intent();
        i.setAction("awais.kpsoft.MyService");
        context.startService(i);

    }

}

}

服务

package awais.soft;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyService extends Service {
private static final String TAG = "MyService";
MediaPlayer player;

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {
    Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();
    Log.d(TAG, "onCreate");

    player = MediaPlayer.create(this, R.raw.is);
    player.setLooping(false); // Set looping
}

@Override
public void onDestroy() {
    Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show();
    Log.d(TAG, "onDestroy");
    player.stop();
}

@Override
public void onStart(Intent intent, int startid) {
    Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
    Log.d(TAG, "onStart");
    player.start();
}

}

推荐答案

一切都很好..:• 问题是与设备。(即Motorolla放大ICS 4.0.3)

Everything was fine..:S The problem was with device..(i.e. Motorolla Zoom ICS 4.0.3)

现在测试上的Galaxy Tab 2.2和做工精细。

Now tested on Galaxy Tab With 2.2 and Working fine..

感谢大家的时间

这篇关于Android的引导进行广播不调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆