2012-02-24 6 views
2

私は、活動から始めるテストライブ壁紙を持っています。現時点では、私は自分のエミュレータでプロジェクトを実行すると、すぐにライブ壁紙選択機能で自分自身を見つけます。あらゆる場所を検索しても、主な活動のボタンが押されて初めてそれを表示させる方法は見つけられません。Android:ボタンからwallpaperserviceをどうやって始めますか?

私の主なアクティビティに静的なブール値を導入しようとしました。これはisnotpressedで、ボタンonClick()のfalseに設定しました。そして、私は壁紙サービスクラスでstopSelf()を使用しましたが、isnotpressedはtrueです。残念ながら、これはどれも役に立たなかったし、とにかく正しい方法でそれについてやっているとは思わない。私もthisを試しましたが、うまくいきませんでした。どんな援助も深くここで評価されるでしょう。

は、ここでの主な活動です:

public class TestProjectActivity extends Activity{ 

static boolean isnotPressed; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    isnotPressed = true; 

final Button b1 = (Button) findViewById(R.id.button1); 

b1.setOnClickListener(new View.OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     // TODO Auto-generated method stub 
     isnotPressed = false; 
    } 
}); 

} 

}

そしてここwallpaperserviceの一部です:

public class MyWallpaperService extends WallpaperService { 




@Override 
public void onCreate() { 
    // TODO Auto-generated method stub 
    super.onCreate(); 

    while(TestProjectActivity.isnotPressed){stopSelf();} 


} 

答えて

0

これを試してみてください:

Intent i = new Intent(); 
    if (Build.VERSION.SDK_INT > 15) 
    { 
     i.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); 
     String pkg = MyPreferencesActivity.class.getPackage().getName(); 
     String cls = MyPreferencesActivity.class.getCanonicalName(); 
     i.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(pkg, cls)); 
    } 
    else 
    { 
     i.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER); 
    } 
    startActivityForResult(i, 0);