[英]how to Remove App Widget from home screen?
How to remove app widget programmatically from home screen?
如何从主屏幕以编程方式删除应用程序小部件?
This question is asked sometimes before But i expect that may be there is any update.以前有时会问这个问题但我希望可能有任何更新。
As of Android O, In your app, you can create a request for the system to pin a widget onto a supported launcher.从 Android O 开始,在您的应用程序中,您可以创建一个请求,让系统将小部件固定到支持的启动器上。
Create the widget in your app's manifest file Call the requestPinAddWidget() method在应用的清单文件中创建小部件调用 requestPinAddWidget() 方法
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { AppWidgetManager mAppWidgetManager = getSystemService(AppWidgetManager.class); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { AppWidgetManager mAppWidgetManager = getSystemService(AppWidgetManager.class);
ComponentName myProvider = new ComponentName(AddWidgetActivity.this,
AppWidgetSmall.class); AppWidgetSmall.class);
Bundle b = new Bundle();
b.putString("ggg", "ggg");
if (mAppWidgetManager.isRequestPinAppWidgetSupported()) {
Intent pinnedWidgetCallbackIntent = new Intent(AddWidgetActivity.this,
AppWidgetSmall.class); AppWidgetSmall.class); PendingIntent successCallback = PendingIntent.getBroadcast(AddWidgetActivity.this, 0, pinnedWidgetCallbackIntent, 0);
PendingIntent successCallback = PendingIntent.getBroadcast(AddWidgetActivity.this, 0, pinnedWidgetCallbackIntent, 0);
mAppWidgetManager.requestPinAppWidget(myProvider, b, successCallback);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.