WEB开发网
开发学院手机开发Android 开发 让自己的Android应用支持appwidget 阅读

让自己的Android应用支持appwidget

 2010-12-18 08:04:06 来源:WEB开发网   
核心提示:import android.content.ComponentName;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnLongClickListene

import android.content.ComponentName;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnLongClickListener;

/**

* 添加appwidget

* @author chroya

*

*/

public class Main extends Activity {

private AppWidgetHost mAppWidgetHost;

private AppWidgetManager mAppWidgetManager;

private WidgetLayout layout;

private static final int REQUEST_PICK_APPWIDGET = 1;

private static final int REQUEST_CREATE_APPWIDGET = 2;

private static final int APPWIDGET_HOST_ID = 0x100;

private static final String EXTRA_CUSTOM_WIDGET = "custom_widget";

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

mAppWidgetManager = AppWidgetManager.getInstance(getApplicationContext());

mAppWidgetHost = new AppWidgetHost(getApplicationContext(), APPWIDGET_HOST_ID);

//开始监听widget的变化

mAppWidgetHost.startListening();

layout = new WidgetLayout(this);

layout.setOnLongClickListener(new OnLongClickListener() {

@Override

public boolean onLongClick(View v) {

addWidget();

return false;

}

});

setContentView(layout);

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (resultCode == RESULT_OK) {

switch (requestCode) {

case REQUEST_PICK_APPWIDGET:

addAppWidget(data);

break;

case REQUEST_CREATE_APPWIDGET:

completeAddAppWidget(data);

break;

}

} else if (requestCode == REQUEST_PICK_APPWIDGET &&

resultCode == RESULT_CANCELED && data != null) {


  点击下载:php?id=1365" rel="nofollow">附件下载

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:自己 Android 应用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接