Top Menu

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday 11 April 2017

How to start an Application on startup?

Hi Friends,

Today we learn how to start an application on device startup.
First, you need the permission in your AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Also in your AndroidManifest.xml, define your service and listen for the BOOT_COMPLETED action:
<service android:name=".MyService" android:label="My Service">
    <intent-filter>
        <action android:name="com.myapp.MyService" />
    </intent-filter>
</service>

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

Then you need to define  the receiver that will get the BOOT_COMPLETED action and start your service.
public class StartMyServiceAtBootReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
            Intent serviceIntent = new Intent(context, MyService.class);
            context.startService(serviceIntent);
        }
    }
}
And now your applicaiton should be running when the phone starts up.

Enjoy!! 
Read more...

Get the phone IMEI number (or serial number)

There are many ways to get the mobile phone IMEI no. You can follow any of this process:

Process 1:
TelephonyManager mngr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); mngr.getDeviceId();

add READ_PHONE_STATE permission to AndroidManifest.xml

Process 2:
telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); deviceId = telephonyManager.getDeviceId(); Log.d(TAG, "getDeviceId() " + deviceId); phoneType = telephonyManager.getPhoneType(); Log.d(TAG, "getPhoneType () " + phoneType);

Process 3:
Also you can get the both IMEI numbers using the below code
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imeiNumber1 = tm.getDeviceId(1); //(API level 23)   
String imeiNumber2 = tm.getDeviceId(2);

Process 4:
telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);

    deviceId = telephonyManager.getDeviceId(); 
    Log.d(TAG, "getDeviceId() " + deviceId);


    phoneType = telephonyManager.getPhoneType();
    Log.d(TAG, "getPhoneType () " + phoneType);

Hope it helps!! :)






Read more...