3

私は Spotify を持っており、アプリケーションでタイトルと曲名を使用したいと考えています。(最終的な目標は、それをライブビュー ウォッチにエクスポートして、Spotify を制御できるようにすることです)

Spotify-Widget があるので、ブロードキャスト レシーバーを追加して、データをウィジェットに送信したいと思います。

したがって、Broadcast レシーバーを追加します。コンセプトを理解している限り、これで十分であり、Spotify がウィジェットに送信するデータを取得できるはずです。

ドキュメンテーションによると、ウィジェット マネージャーでできることはすべてブロードキャスト レシーバーでできるので、ブロードキャスト レシーバーで十分だと思います。

on_receive が呼び出されるとすぐに、デバッグ ログ エントリとトーストを作成したので、少なくとも何かがあるはずです。

エラー メッセージから、ウィジェットを持っていない場合、Spotify は常にウィジェットにデータを送信しようとすることがわかります。間違いは私の側にあると確信しています。

次のように私のコード:

(簡潔にするために短縮され、後でサービスまたは何かとして、今のところ)テキストビューは後でタイトルを表示するものとします

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // für den Song

    IntentFilter iF = new IntentFilter();


    iF.addCategory("ComponentInfo");
    iF.addCategory("com.spotify.mobile.android.service.SpotifyIntentService");
    iF.addCategory("com.spotify.mobile.android.service.SpotifyService");


    iF.addAction("com.spotify.mobile.android.ui.widget.SpotifyWidget");
    iF.addAction("ComponentInfo");
    iF.addAction("com.spotify");
    iF.addAction("com.spotify.mobile.android.service.SpotifyIntentService");
    iF.addAction("com.spotify.mobile.android.service.SpotifyService");


    iF.addAction("com.android.music.metachanged");
    iF.addAction("com.android.music.playstatechanged");
    iF.addAction("com.android.music.playbackcomplete");
    iF.addAction("com.android.music.queuechanged");
    iF.addAction("com.spotify.mobile.android.ui");

    registerReceiver(mReceiver, iF);

    // albumtext = (TextView) findViewById(R.id.albumText);

}

    private BroadcastReceiver mReceiver = new BroadcastReceiver() {

                @Override
                public void onReceive(Context context, Intent intent)
                {

                    Log.d("onReceive launched", "kekse");

                            String action = intent.getAction();
                            String cmd = intent.getStringExtra("command");

                            String com = intent.getStringExtra("ComponentInfo");

                            Log.d("mIntentReceiver.onReceive ", action + " / " + cmd+ " / "+ com);

                            String artist = intent.getStringExtra("artist");
                            String album = intent.getStringExtra("album");
                            String track = intent.getStringExtra("track");
                            Log.d("Music",artist+":"+album+":"+track);

                            Toast.makeText(context, "Command : "+cmd+"\n Artist : "+artist+" Album :"+album+"Track : "+track+" " , Toast.LENGTH_SHORT).show();

                }
    };

完全を期すために、ここに私のマニフェストファイルがあります

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.KarlheinzMeier.SpotifyController"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />


<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name="de.KarlheinzMeier.SpotifyControllerActivity"
        android:label="@string/app_name" >

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.ComponentInfo" />
    </intent-filter>

    <receiver android:name="com.spotify.mobile.android.ui.widget.SpotifyWidget" android:label="Kekse">
    <intent-filter>
        <action android:name="com.spotify.mobile.android.service.SpotifyService" />
         <action android:name="com.spotify.mobile.android.service.SpotifyIntentService" />
    </intent-filter>

</receiver>

    </activity>

</application>

</manifest>

PS: 内部データ フォーマットが変更されるとすぐに、私のアプリは壊れます。これは私的使用のみであるため、気にしません。それについての議論はしないでくださいAPIがあれば、何もないのでそれを取ります...

4

0 に答える 0