Make your android widget default on android home screen

124 Views Asked by At

I have system level privileges and I want to be have my widget be a default item on the devices home screen.

What I have tried using the following in my manifest

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

and this in the application tag in the manifest

<receiver
        android:name=".StartOnBootReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
</receiver>

This is in the class called StartOnBootReceiver.java

public class StartOnBootReciever extends BroadcastReceiver {

    private static final String TAG = "rwid_StartOnBootReceiver";

    public StartOnBootReciever(){
    }

    @Override
    public void onReceive(Context context, Intent intent){
        Log.d(TAG, "Your app is alive");
        final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        final AppWidgetHost appWidgetHost =  new AppWidgetHost(context,R.id.Acceleration_Widget);

        int appWidgetId = appWidgetHost.allocateAppWidgetId();
        ComponentName comp = new ComponentName(context.getPackageName(),WidgetActivity.class.getName());
        Log.d(TAG,""+appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,comp));

        Intent intent1 = new Intent(context, WidgetActivity.class);
        intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent1);
    }
}

I know that this code runs when the device boots up due to my logging but I cant seem to get the widget on my home screen.

0

There are 0 best solutions below