我尝试用服务创建一些应用程序(对于backsound),我尝试在手机中运行应用程序,但没有问题,但是当我的朋友运行我的应用程序时,它不起作用,我的手机是Jellybean而我的朋友是棒棒糖。
这是我的代码活动:
package com.example.michael.fordear;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.widget.ImageView;
import com.example.michael.switchcard.R;
/**
* Created by Michael on 19/11/2015.
*/
public class frag1 extends Activity
{
ImageView iv;
MyTimer tim1;
MyTimer1 tim2;
MyTimer2 tim3;
MediaPlayer mediaPlayer;
BackgroundSoundService sv;
Intent svc;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.frag1);
iv = (ImageView) findViewById(R.id.open);
iv.setImageResource(R.drawable.open);
svc=new Intent(this, BackgroundSoundService.class);
tim1 = new MyTimer(5000,10);
tim1.start();
startService(svc);
}
public class MyTimer extends CountDownTimer
{
public MyTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
@Override
public void onFinish() // Jika waktu sesion habis
{
// TODO Auto-generated method stub
iv.setImageResource(R.drawable.ms1);
tim2 = new MyTimer1(35000, 10);
tim2.start();
Log.d("TAG", "fin");
}
@Override
public void onTick(long millisUntilFinished)
{
// TODO Auto-generated method stub
}
}
public class MyTimer1 extends CountDownTimer
{
public MyTimer1(long millisInFuture, long countDownInterval)
{
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
@Override
public void onFinish() // Jika waktu sesion habis
{
// TODO Auto-generated method stub
iv.setImageResource(R.drawable.ms2);
Log.d("TAG", "fin");
tim3 = new MyTimer2(6000, 10);
tim3.start();
}
@Override
public void onTick(long millisUntilFinished)
{
// TODO Auto-generated method stub
}
}
public class MyTimer2 extends CountDownTimer
{
public MyTimer2(long millisInFuture, long countDownInterval)
{
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
@Override
public void onFinish() // Jika waktu sesion habis
{
// TODO Auto-generated method stub
iv.setImageResource(R.drawable.end);
Log.d("TAG", "fin");
}
@Override
public void onTick(long millisUntilFinished)
{
// TODO Auto-generated method stub
}
}
@Override
public void onBackPressed()
{
super.onBackPressed();
onStop();
finish();
}
}
这是服务
package com.example.michael.fordear;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import com.example.michael.switchcard.R;
/**
* Created by Michael on 19/11/2015.
*/
public class BackgroundSoundService extends Service
{
private static final String TAG = null;
MediaPlayer player;
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate()
{
super.onCreate();
player = MediaPlayer.create(this, R.raw.cobamp3);
player.setLooping(false); // Set looping
player.setVolume(100, 100);
}
public int onStartCommand(Intent intent, int flags, int startId) {
player.start();
return 1;
}
public void onStart(Intent intent, int startId) {
// TO DO
}
public IBinder onUnBind(Intent arg0) {
// TO DO Auto-generated method
return null;
}
public void onStop() {
}
public void onPause() {
}
@Override
public void onDestroy() {
player.stop();
player.release();
}
@Override
public void onLowMemory() {
}
}
所以我的朋友可以在他的Lollipop Android中运行我的应用程序吗?