J'ai une radio Android qui ne démarre pas automatiquement les applications, mais il peut démarrer des applications à partir de widgets. Je veux créer un widget qui va démarrer différentes applications que je choisis mais je veux qu'elles ouvrent seulement d'autres applications puis les ferment ou ouvrent en arrière-plan donc une fois toutes les applications démarrées, l'écran d'accueil est toujours affiché. J'ai déjà un AppWidgetProvider simple que j'utilise d'un autre projet:Android créer un widget pour démarrer d'autres applications, mais en arrière-plan
public class AppStarterWidget extends AppWidgetProvider {
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
}
@Override
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager,
final int[] appWidgetIds) {
super.onUpdate(context, appWidgetManager, appWidgetIds);
final Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
for (int widgetId : appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.widget_layout);
remoteViews.setInt(R.id.btnStartActivity, "setBackgroundResource",
R.drawable.circle_off);
try {
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.setComponent(new ComponentName("com.my.app", "Qualified name"));
PendingIntent pendingIntent = PendingIntent.getActivity(
context, 0, intent, 0);
remoteViews.setOnClickPendingIntent(R.id.btnStartActivity, pendingIntent);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
//handler.postDelayed(this, 10000);
} catch (ActivityNotFoundException e) {
Toast.makeText(context.getApplicationContext(),
"There was a problem loading the application: ",
Toast.LENGTH_SHORT).show();
}
}