安卓8.0以上的点击桌面插件打电话,判断点击控件
2018-03-01 12:37
309 查看
NewAppWidget.java
new_app_widget.xml
package com.linyb.widget_click_call; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetProvider; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.widget.RemoteViews; /** * Implementation of App Widget functionality. */ public class NewAppWidget extends AppWidgetProvider { private static final String CLICK_ACTION="callChangePic"; public void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { // Construct the RemoteViews object RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.new_app_widget); ComponentName watchWidget = new ComponentName(context,NewAppWidget.class); views.setOnClickPendingIntent(R.id.btn,getPendingSelfIntent(context,CLICK_ACTION)); // Instruct the widget manager to update the widget appWidgetManager.updateAppWidget(watchWidget, views); } //小部件被添加时或者每次小部件更新时都会调用一次该方法,,每 // 个周期小部件都会自动更新一次,不是点击的时候更新, // 而是到指定配置文件时间的时候才更新 @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // There may be multiple widgets active, so update all of them for (int appWidgetId : appWidgetIds) { updateAppWidget(context, appWidgetManager, appWidgetId); } } @Override public void onEnabled(Context context) { // Enter relevant functionality for when the first widget is created } @Override public void onDisabled(Context context) { // Enter relevant functionality for when the last widget is disabled } protected PendingIntent getPendingSelfIntent(Context context, String action) { Intent intent = new Intent(context, getClass()); intent.setAction(action); return PendingIntent.getBroadcast(context, 0, intent, 0); } @Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if (CLICK_ACTION.equals(intent.getAction())) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); RemoteViews remoteViews; ComponentName watchWidget; remoteViews = new RemoteViews(context.getPackageName(), R.layout.new_app_widget); watchWidget = new ComponentName(context, NewAppWidget.class); remoteViews.setTextViewText(R.id.appwidget_text, "已经点击"); remoteViews.setImageViewResource(R.id.image_view, R.mipmap.ic_launcher_round); appWidgetManager.updateAppWidget(watchWidget, remoteViews); Intent call_intent=new Intent(Intent.ACTION_DIAL, Uri.parse("tel:112" )); call_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(call_intent); } } }
new_app_widget.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#09C" android:padding="@dimen/widget_margin"> <TextView android:id="@+id/appwidget_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_margin="8dp" android:background="#09C" android:contentDescription="@string/appwidget_text" android:layout_gravity="center" android:text="@string/appwidget_text" android:textColor="#ffffff" android:textSize="24sp" android:textStyle="bold|italic" /> <ImageView android:id="@+id/image_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher" android:layout_gravity="left|bottom"/> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#224433" android:layout_gravity="right|top" /> </FrameLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.linyb.widget_click_call"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".NewAppWidget"> <intent-filter> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> </intent-filter> <meta-data android:name="android.appwidget.provider" android:resource="@xml/new_app_widget_info" /> </receiver> </application> </manifest>
相关文章推荐
- 一个最简单的点击桌面小部件图片打电话 8.0以下可以使用
- 安卓快速实现关键字变色,搜索字变红,点击字体打电话,textview斜体,电商价格删除线,绿色下划线,图片(表情,图文混排) textview超链接跳转
- 安卓笑话桌面插件
- DatePicker 控件在5.0以上版本 焦点释放问题 手动输入点击确定按钮不能正确获取到日期优化
- 安卓桌面插件(窗口小部件)的各种问题
- Extjs DateTime 日期时间选择控件 (非点击日期强制选择) 支持4.0以上
- 安卓中控件触摸事件和点击事件的处理
- 安卓静默安装应用之创建手机桌面图标,并点击图标安装新的应用
- Myeclipse8.0以上版本插件添加
- wxWidgets 树状控件(wxTreeCtrl)点击各子项事件消息的判断
- 使用Android Studio开发widget安卓桌面插件
- 安卓控件水纹点击效果
- 安卓控件拖动和点击事件冲突处理----可拖动的FloatingActionButton
- iOS判断点击的区域在某个控件之外的方法
- 根据鼠标左键点击判断是哪个控件
- 安卓笔记android中控件点击事件实现的几种方式
- [安卓] 如何判断桌面已经添加APP应用的快捷方式
- 安卓桌面小控件App Widget
- 安卓控件使用系列3:TextView点击连接跳转页面
- 为插件中的主程序创建快捷桌面,点击创建的快捷桌面进入主程序的插件并传递值进去