ウィジットからのアプリ起動について

1,728 views
Skip to first unread message

大和

unread,
Sep 11, 2010, 4:45:37 AM9/11/10
to Android-SDK-Japan
ウィジットのボタンを押すことでウィジット本体のアプリを起動しようとしています。
---------------------------------------------------------------------------------------------------------
if (ACTION_MY_CLICK.equals(intent.getAction())) {
Intent intentws=new
Intent(this,yamato.ave.ktidews.ktideView.class);
startActivity(intentws);
}

これを実行すると下記エラーになってしまいます。
---------------------------------------------------------------------------------------------------------
This kind of launch is configured to open the Debug perpective when it
suspends.

ウィジットからのアプリ起動はIntentではないのでしょうか?

misuya yoshihiko

unread,
Sep 12, 2010, 6:37:50 AM9/12/10
to android-...@googlegroups.com
To:大和さん

ウェッジウッドは詳しくないのですが、アプリから別のアプリを立ち上げる場合は
//この部分
Intent(this,yamato.ave.ktidews.ktideView.class);

//例1
Intent i = new Intent(Intent.ACTION_VIEW);
ComponentName componentName = new ComponentName(DEFAULT_PACKAGE, DEFAULT_CLASS);
i.setComponent(componentName);
startActivity(i);

とか
//例2
Intent i = new Intent(Intent.ACTION_MAIN);
componentName = new ComponentName(DEFAULT_PACKAGE, DEFAULT_CLASS);
i.setComponent(componentName);
startActivity(i);

と指定しています。
参考にしてみてください。

MANO

2010年9月11日17:45 大和 <gfa0...@gmail.com>:

> --
> このメールは Google グループのグループ「Android-SDK-Japan」の登録者に送られています。
> このグループに投稿するには、android-...@googlegroups.com にメールを送信してください。
> このグループから退会するには、android-sdk-ja...@googlegroups.com にメールを送信してください。
> 詳細については、http://groups.google.com/group/android-sdk-japan?hl=ja からこのグループにアクセスしてください。
>
>
>

--
******************
 (株)ウェブスターシステム
 ITソリューション事業部 第3部
 翠簾屋 良彦
******************

hirokuma ueno

unread,
Sep 12, 2010, 7:32:27 AM9/12/10
to android-...@googlegroups.com
ウィジェットからの場合、対象となるView(この場合はボタンですね)に
あらかじめsetOnClickPendingIntent()を設定しておき、ボタンクリック時に
PendingIntentが発行される形を取ります。

ここら辺がわかりやすいかと思います。
http://codezine.jp/article/detail/4496

--
//ueno

大和

unread,
Sep 12, 2010, 9:12:35 PM9/12/10
to Android-SDK-Japan
misuya yoshihikoさん
hirokuma uenoさん
貴重なコメントありがとうございます。

早速、コメントを精査して試してみます。
後程、報告致します。

大和

unread,
Sep 17, 2010, 7:01:29 PM9/17/10
to Android-SDK-Japan
お二人のコメントを参考にして下記を実行しましたがWidgetをクリックするとアボートしてしまいます。
あやしいの下記
//----------ここの部分がわかりません!(はじめ)---------
部分のような気がするのですが・・・

------------------------全ソース-------------------------
package yamato.ave.ktidews;
import android.app.PendingIntent;
import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.widget.RemoteViews;
public class ktideProvider extends AppWidgetProvider {
private static final String ACTION_MY_CLICK =
"yamato.ave.ktidews.ktideProvider.ACTION_MY_CLICK";

@Override
public void onUpdate(Context context, AppWidgetManager
appWidgetManager, int[] appWidgetIds) {
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
}
public static class MyService extends Service {
@Override
public void onStart(Intent intent, int startId) {
ComponentName thisWidget = new
ComponentName(this,ktideProvider.class);
AppWidgetManager manager =
AppWidgetManager.getInstance(this);
RemoteViews remoteViews = new
RemoteViews(getPackageName(), R.layout.ktide_provider);
if (ACTION_MY_CLICK.equals(intent.getAction())) {
//----------ここの部分がわかりません!(はじめ)------------------------
Intent i = new Intent(Intent.ACTION_VIEW);
ComponentName componentName = new
ComponentName(this,yamato.ave.ktidews.ktideView.class);
i.setComponent(componentName);
startActivity(i);
//----------ここの部分がわかりません!(おわり)------------------------
}
}
Intent clickIntent = new Intent();
clickIntent.setAction(ACTION_MY_CLICK);
PendingIntent pendingIntent =
PendingIntent.getService(this,0,clickIntent,0);

remoteViews.setOnClickPendingIntent(R.id.Button01,pendingIntent);
manager.updateAppWidget(thisWidget,remoteViews);
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
}

hirokuma ueno

unread,
Sep 17, 2010, 7:51:30 PM9/17/10
to android-...@googlegroups.com
かっこ {} の数があってないようですが、そこは大丈夫でしょうか。
(単なるコピーミスだと思ってます)

どうしたいのかソースから読み取るのが難しいのですが、
 ・AppWidget起動時にサービスを起動させたい
 ・AppWidgetクリック時にサービスを起動させたい
 ・サービスからActivityを起動させたい
ということでしょうか。

サービスから Activityを起動させるというのは、どこかのML で見た気がします。
(最近だったと思うのですが、見つけられませんでした。。)

サービスとは関係なく、単に AppWidget をタッチして Activityを起動させたい
のであれば、startActivity() は必要ありません。
(使って起動する方法はあるのかもしれませんが、よく知りません。)
PendingIntent ではサービスではなく、Activityを起動するように
変更すればよいと思います。

AppWidget は普通のアプリとは別物と割り切った方がよさそうです。

--
//ueno

yoshihiko misuya

unread,
Sep 18, 2010, 2:40:03 AM9/18/10
to android-...@googlegroups.com
TO:大和 さん

まず、私の勘違いかもしれませんが、Widget と 起動アプリは別にあり
2プログラム(.apk)があると思っていました。
その起動には、ご紹介した2つのアプリ間で起動するstartActivity(i);が参考になると
思っておりました。

ソースを拝見するとWidgetと起動したいActivityは同一アプリ(.apk)にあるように
見受けられます。

Widgetの使い方であれば、次の記事が参考になりそうです。
http://japan.internet.com/developer/20091127/26.html

この記事を見ると、
Intent configIntent =
new Intent(context, ImagesWidgetConfiguration.class);
configIntent.putExtra(
AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
configIntent.setData(Uri.withAppendedPath(Uri.Parse
(ImagesWidgetProvider.URI_SCHEME + "://widget/id/"),
String.valueOf(appWidgetId)));

上記のようなコードで、画面を呼び出しているように見えます。

下記のコードで、OnClickを設定しているように見えます。
PendingIntent pendingIntent = PendingIntent.getActivity
(context, 0, configIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
remoteView.
setOnClickPendingIntent(R.id.config, pendingIntent);

                          以 上


2010年9月18日8:01 大和 <gfa0...@gmail.com>:

大和

unread,
Sep 19, 2010, 3:01:16 AM9/19/10
to Android-SDK-Japan
重ねてのご意見をありがとうございます。
もう一度アドバイスを読ませて頂いて挑戦します。

質問の背景が不足していて申訳ありません。
遅ればせながら概要を書きます。

対象アプリは「携帯潮汐」というものです。
http://homepage1.nifty.com/ave/android/ktide/ktidews.html
これのウィジェットからアプリ本体を起動出来るようにしたいと思っています。

アプリ構造は下記のようになっています。
ktideWS(アプリ本体兼ウィジェット設定)

ktideProvider(ウィジェットプロバイダー)

MyService(ウィジェット兼ボタンクリックでアプリ本体起動))

ktideWS(アプリ本体)

>かっこ {} の数があってないようですが、そこは大丈夫でしょうか。
これは単純化時のコピーミスです。

Hideki Yoshino

unread,
Sep 21, 2010, 9:26:09 PM9/21/10
to Android-SDK-Japan
こんな感じ行けました。 アプ本体(ShoppingListActivity.class)とウィジェットは同じパッケージです。

Intent intent = new Intent(context, ShoppingListActivity.class);
PendingIntent appIntent = PendingIntent.getActivity(context, 0,
intent, 0);
remoteViews.setOnClickPendingIntent(R.id.widget, appIntent);

Shoya Tsukada

unread,
Sep 17, 2010, 10:24:44 PM9/17/10
to android-...@googlegroups.com
がぶです。

> This kind of launch is configured to open the Debug perpective when it
suspends.

これってEclipseのダイアログですよね?
ブレークポイントで止まってませんか?

> お二人のコメントを参考にして下記を実行しましたがWidgetをクリックするとアボートしてしまいます。

ログ(Exceptionなど)を貼って頂ければ分かるかもしれません。

2010年9月18日8:51 hirokuma ueno <ueno...@gmail.com>:

> --
> このメールは Google グループのグループ「Android-SDK-Japan」の登録者に送られています。
> このグループに投稿するには、android-...@googlegroups.com にメールを送信してください。
> このグループから退会するには、android-sdk-ja...@googlegroups.com にメールを送信してください。
> 詳細については、http://groups.google.com/group/android-sdk-japan?hl=ja からこのグループにアクセスしてください。
>
>

--
塚田 翔也
Shoya Tsukada
tsukada...@gmail.com
Twitter: http://twitter.com/gabu
Blog: http://d.hatena.ne.jp/gabuchan/
Google group: http://groups.google.com/group/android-nagoya-tsubu

abe akio

unread,
Sep 22, 2010, 3:54:48 AM9/22/10
to android-...@googlegroups.com
皆様、再三のありがとうございます。
頂いたコメントの中でHideki Yoshinoさんの事例が、私のアプリ構造と同じようなので下記で実行してみましたがウィジェットボタンをクリックしての反応なしです。
思いはktideWS.classを起動させたいのですが・・・細かい質問で申訳ありません!!
-------------------------------------

package yamato.ave.ktidews;
import android.app.PendingIntent;
import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.widget.RemoteViews;
public class ktideProvider extends AppWidgetProvider {
   private static final String ACTION_MY_CLICK = "yamato.ave.ktidews.ktideProvider.ACTION_MY_CLICK";
   @Override
   public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        Intent serviceIntent = new Intent(context, MyService.class);
        context.startService(serviceIntent);
 }
    public static class MyService extends Service {
        @Override
        public void onStart(Intent intent, int startId) {
            ComponentName thisWidget = new ComponentName(this,ktideProvider.class);
            AppWidgetManager manager = AppWidgetManager.getInstance(this);
            RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.ktide_provider11);

            Intent clickIntent = new Intent();
            clickIntent.setAction(ACTION_MY_CLICK);
            if (ACTION_MY_CLICK.equals(intent.getAction())) {
             clickIntent = new Intent(this, ktideWS.class);

Hideki Yoshino

unread,
Sep 22, 2010, 12:51:24 PM9/22/10
to android-...@googlegroups.com
このif condition なしでもだめですかね。
if (ACTION_MY_CLICK.equals(intent.getAction())) {

ちなみに自分はbuildUpdateで設定してます。
/**
* Builds the update.
*
* @param context the context
*
* @return the remote views
*/
public RemoteViews buildUpdate(Context context) {
DBHelper dbHelper = new DBHelper(context);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.appwidget_provider);
try {

UserListGroup userListGroup =
dbHelper.dbUserListGroup.getDefaultUserListGroup();
if (userListGroup != null) {
List<UserList> userLists =
dbHelper.dbUserList.getUserLists(userListGroup);
List<String> userListsArray = new ArrayList<String>();
int userListsSize = userLists.size();
for (int i = 0; i < userListsSize; i++) {
UserList userList = userLists.get(i);
if (!userList.isCompleted()) {
userListsArray.add(userList.getUserListName());
}
}
int[] lines = {R.id.line0,
R.id.line1,
R.id.line2,
R.id.line3,
R.id.line4,
R.id.line5,
R.id.line6,
R.id.line7,
R.id.line8,
R.id.line9};
int userListsArraySize = userListsArray.size();
for (int i = 0; i < lines.length; i++) {
if (i < userListsArraySize) {
views.setTextViewText(lines[i], userListsArray.get(i));
} else {
views.setTextViewText(lines[i], "");
}
}
}

} finally {
dbHelper.cleanup();
}

Intent intent = new Intent(context, ShoppingListActivity.class);

PendingIntent appIntent = PendingIntent.getActivity(context, 0,
intent, 0);

views.setOnClickPendingIntent(R.id.widget, appIntent);

return views;
}


2010/9/22 abe akio <gfa0...@gmail.com>:

> --
> このメールは Google グループのグループ「Android-SDK-Japan」の登録者に送られています。
> このグループに投稿するには、android-...@googlegroups.com にメールを送信してください。
> このグループから退会するには、android-sdk-ja...@googlegroups.com にメールを送信してください。
> 詳細については、http://groups.google.com/group/android-sdk-japan?hl=ja
> からこのグループにアクセスしてください。
>

--
Hideki Yoshino
hideki....@gmail.com

Hideki Yoshino

unread,
Sep 22, 2010, 1:00:24 PM9/22/10
to android-...@googlegroups.com
buildUpdateはonStartからcallしていました。

/* (non-Javadoc)
* @see android.app.Service#onStart(android.content.Intent, int)
*/


@Override
public void onStart(Intent intent, int startId) {

// Build the widget update for today
RemoteViews updateViews = buildUpdate(this);

// Push update for this widget to the home screen
ComponentName thisWidget = new ComponentName(this,
ListWidgetProvider.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, updateViews);
}
}

2010/9/22 Hideki Yoshino <hideki....@gmail.com>:

--
Hideki Yoshino
hideki....@gmail.com

大和

unread,
Sep 23, 2010, 1:37:58 AM9/23/10
to Android-SDK-Japan
Hideki Yoshinoさん
丁寧な説明をありがとうございました。

掲載のサンプルで「 ウィジットからのアプリ起動」、確認しました。

あとは私のアプリへの組込ですが、他のアクションで
if (ACTION_MY_CLICK.equals(intent.getAction())) {
を使っているので工夫してみます。


Reply all
Reply to author
Forward
0 new messages