2012年12月9日 星期日

Filter Broadcast List


Filter Broadcast List

addDataSchemeaddAction

ACTION_BATTERY_CHANGED當電量產生變化

ACTION_BATTERY_LOW電量低

ACTION_BATTERY_OKAY電量正常

ACTION_POWER_CONNECTED連接充電

ACTION_POWER_DISCONNECTED拔除充電

ACTION_BOOT_COMPLETED開機完成

ACTION_REBOOT重新啟動

ACTION_SHUTDOWN關機

ACTION_SCREEN_OFF螢幕關閉

ACTION_SCREEN_ON螢幕開啟

ACTION_CAMERA_BUTTON當按下Camera按鈕

ACTION_HEADSET_PLUG耳機被插上或拔下

ACTION_CONFIGURATION_CHANGED Configuration(orientation, locale...)螢幕旋轉

ACTION_DATE_CHANGED當日期改變

ACTION_INPUT_METHOD_CHANGED輸入法改變

ACTION_LOCALE_CHANGED地區改變

ACTION_TIMEZONE_CHANGED時區改變

ACTION_TIME_CHANGED時間改變

ACTION_TIME_TICK時間被變更

ACTION_WALLPAPER_CHANGED當桌布變更

ACTION_GTALK_SERVICE_CONNECTEDGtalk連線建立

ACTION_GTALK_SERVICE_DISCONNECTEDGtalk連線中斷
fileACTION_MEDIA_MOUNTEDSDCard掛載
ACTION_MEDIA_UNMOUNTEDSDCard 移除

ACTION_NEW_OUTGOING_CALL播打電話
packageACTION_PACKAGE_ADDED安裝一個新的程式
ACTION_PACKAGE_CHANGED即有的程式被變更
ACTION_PACKAGE_DATA_CLEARED程式的資料被清除
ACTION_PACKAGE_FIRST_LAUNCH程式第一次被執行
ACTION_PACKAGE_RESTARTED程式被重新執行
ACTION_PACKAGE_INSTALL安裝程式
ACTION_PACKAGE_REMOVED程式移除
ACTION_PACKAGE_REPLACED程式被取代

ACTION_UMS_CONNECTEDUSB Mount

ACTION_UMS_DISCONNECTEDUSB Unmount

ACTION_USER_PRESENTwake up

2012年12月8日 星期六

Start service at boot time for android 4.0


I can't not start service when I want to start service at boot time for android 4.0, in android. My code is below:
> public class StartUpReceiver extends BroadcastReceiver{   @Override
> public void onReceive(Context context, Intent intent) { String
> action = intent.getAction(); if
> (action.equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")) {
> Intent myIntent = new Intent(context, StartAUT_Service.class);
> Log.i("Broadcast", "startService on boot time:." + myIntent);
> context.startService(myIntent); }
> } }



<uses-permission
android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
> <application android:icon="@drawable/icon" android:label="@string/app_name">
> <receiver android:name="com.Android.Exercise.StartUpReceiver" android:exported="false">
> <intent-filter>
> <action android:name="android.intent.action.BOOT_COMPLETED"/>
> <action android:name="StartInstrument" />
> <action android:name="PrintControlName" />
> </intent-filter>
> </receiver>
> <service android:enabled="true" android:name="StartAUT_Service">
> <intent-filter>
> <action android:name="com.Android.Exercise.StartAUT_Service" />
> </intent-filter>
> </service>
> </application>
And in LogCat show Shutting down VM when i run above project, so my broadcast don't receive action. Plz help me.!!! Thanks so much.
share|improve this question
feedback


In your onResume method of a BroadCastReceiver class put following code
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onReceive(context, intent);

if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent i = new Intent(context, yourService.class);
i
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context
.startService(i);

}
}
share|improve this answer


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

Service


Hello,
Now we are going to learn how to start a service at boot time, i.e. to start our service when device starts up.
First we have to create a BroadcastReceiver which will be started when boot completes as
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyStartupIntentReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
}
}
onRecieve will be first called when the BroadcastReceiver MyStartupIntentReceiver starts.
Next make an entry of this receiver in AndroidManifest.xml as
<receiver android:name="MyStartupIntentReceiver">
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
Here in intent filter we have declared the action as android.intent.action.BOOT_COMPLETED , so that this receiver and intent with action android.intent.action.BOOT_COMPLETED
Now this receiver will be intimated when boot completes
Next if we want to start a service then the procedure is as follows
Create a Service as
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MyService extends Service {

@Override
public IBinder onBind(Intent intent) {

return null;

}

@Override
public void onCreate() {
super.onCreate();

Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();

}

@Override
public void onDestroy() {
super.onDestroy();

Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();

}

@Override
public void onStart(Intent intent, int startId) {

super.onStart(intent, startId);

Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();

}
}
Make an entry of this service in AndroidManifest.xml as
<service android:name="MyService">
<intent-filter>
<action
android:name="com.wissen.startatboot.MyService" />
</intent-filter>
</service>
Now start this service in the BroadcastReceiver MyStartupIntentReceiver’s onReceive method as
 public void onReceive(Context context, Intent intent) {
Intent serviceIntent = new Intent();
serviceIntent.setAction("com.wissen.startatboot.MyService");
context.startService(serviceIntent);

}
Next you can write the code that you want to execute when device boots up in the BroadcastReceiver or in the Service

registerReceiver in service


package com.example.bcris;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;

public class mservice extends Service{

@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate() {
        super.onCreate();
        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
        BR r = new BR();
        registerReceiver(r,filter);
     
        IntentFilter filter2 = new IntentFilter(Intent.ACTION_SCREEN_ON);
        BR r2 = new BR();
        registerReceiver(r2,filter2);
     
}

}


---------------------------------------------------------------------------------------------
<service android:name="mservice" >
            <intent-filter>
                <action android:name="com.example.bcris.mservice" />
            </intent-filter>
        </service>

broadcast receiver, service,
Related Posts Plugin for WordPress, Blogger...