2

Android アプリの開発は初めてですが、JAVA でのプログラミングと一般的な知識は十分にあります。Androidのデフォルトの音楽プレーヤー(Google Play Musicなど)に音楽ファイルをキューに入れることができるAndroid用のアプリを作成しようとしています。私のアプリはどの曲をいつ再生するかを決定しますが、本格的な音楽プレーヤー アプリを作成したくありません。既存のプレーヤー アプリに新しい音楽をフィードしたいだけです。

私は、コンテンツを音楽プレーヤーにフィードし、おそらくプレーヤー自体を制御できる「アプリ間」通信のようなものを探しています (おそらく Intent を使用していますか?)。

そのような機能がアンドロイドに存在するかどうかはわかりませんので、他の代替案も歓迎します。また、問題を適切に説明していない場合はお知らせください。

4

1 に答える 1

1

Intents are a very powerful feature of Android to which there isn't any direct analog in Java. What you want to use is a mechanism known as an implicit Intent. Normally, when you launch one activity from another, you create an Intent and specify which activity to start. With an implicit Intent, you provide an action (Intent.ACTION_VIEW) and data (a URI pointing to a music file). Using an implicit Intent, you have a piece of data handled without knowing in advance which Activity will do the handling.

When you pass your Intent to startActivity(), the OS will attempt to resolve the data in the best way possible, typically popping up a list of apps that can possibly handle your data. The user selects the appropriate app and that app handles the Intent, playing your music file. Any app that registers as a service capable of potentially handling your data will show up in the list. After passing the Intent, your activity will go into the background, and the app handling the intent will come to the foreground.

Once the user has selected an app to handle the Intent from your Activity, that app will always be used to handle that kind of Intent by your Activity until you delete your own app's data.

Take a look at the official doc to get yourself started and then ask a new question when you have a more specific problem you're trying to address.

Here's a code sample that demonstrates a very simple implicit Intent example, by which a URL is opened without knowing which browser will open it:

package com.marsatomic.intentimplicitdemo;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity
{
    public final static Uri URI = Uri.parse("http://www.marsatomic.com");

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button buttonConnect = (Button)findViewById(R.id.button_connect);
        buttonConnect.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v)
            {
                Intent i = new Intent(Intent.ACTION_VIEW, URI);
                startActivity(i);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}
于 2013-05-20T05:47:18.710 に答える