Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
388 views
in Technique[技术] by (71.8m points)

android - How to get Boot_Complete intent in HTC when i use 'poweroff' for reboot?

I want to start service once i get BOOT_COMPLETE intent. In HTC explorer there are 2 options for reboot those are 'poweroff' and 'restart'. When i use 'restart' i am getting BOOT_COMPLETE intent properly. But when i use 'poweroff' not getting BOOT_COMPLETE intent so i am not able to start service. Is their any intent i can get only after reboot in HTC?

I have been surfing Google, could not find any hint. I am stuck please help me out

I used this code <action android:name="android.intent.action.BOOT_COMPLETED"/> in manifest but no use

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Some HTC devices can enable a "fast boot" feature that is more like a deep hibernation and not a real reboot and therefore should not give the BOOT_COMPLETE intent. Also make sure that the app is not installed on the SD card as it might not receive the BOOT_COMPLETED because of that.

This might also be interesting:

http://commonsware.com/blog/2011/07/13/boot-completed-regression-confirmed.html

http://arthurfmay.blogspot.jp/2011/06/broadcastreceiver-bootcompleted-and.html

And especially this where the "fast boot" option is being mentioned:

http://groups.google.com/group/android-developers/browse_thread/thread/56562e4de4919dc6

Edit:

How about simply using:

Intent.ACTION_SCREEN_ON

And you can then check if the service is running:

public static boolean ServiceRunning(Context cx) 
{   ActivityManager manager = (ActivityManager) cx.getSystemService(Context.ACTIVITY_SERVICE);
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
    {   if ("<<<service name goes here>>>".equals(service.service.getClassName()))
        {   return true;
        }
    }
    return false;
}

And if it isn't just start it:

public static void ServiceCheck(Context cx)
{   if(ServiceRunning(cx) == false)
    {   Intent svc = new Intent(".<<<Servicename>>>");
        cx.startService(svc);
        Log.i("Service-Check","Service Starting");
    }
    else
    {   Log.i("Service-Check","Service Existing");
    }
}   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...