我想阻止我的音乐播放器应用程序在每次应用程序启动时扫描目录中的音频文件.我怎样才能做到这一点?
我一直在使用以下代码来扫描音频文件.
public void getSongList() {
ContentResolver contentResolver=getContentResolver();
Uri musicUri=android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = contentResolver.query(musicUri, null, null, null, null);
if(musicCursor!=null && musicCursor.moveToFirst()) {
//get columns
int titleColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex
(android.provider.MediaStore.Audio.Media.ARTIST);
int albumIDColumn = musicCursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID);
//add songs to list
do {
long thisId = musicCursor.getLong(idColumn);
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
long thisAlbumID=musicCursor.getLong(albumIDColumn);
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Bitmap albumArtBitMap=null;
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, thisAlbumID);
try {
albumArtBitMap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), albumArtUri); …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个应用程序,允许其他 Android 手机充当扬声器,从而创建一个类似派对的东西。该应用程序类似于三星提供的群组游戏功能。
为了实现此功能,我决定执行以下步骤 -
**面临的问题 - ** 实现此功能后,我注意到两个 Android 设备都有不同的系统时间,因此我使用 ClockSync 应用程序同步系统时间,该应用程序使用 NTP 来同步时间。我不希望我的用户使用需要 root 访问权限的第三方应用程序。那么如何同步两部安卓手机的时钟呢?我该如何解决这个问题?
编辑-我使用下面的AsyncTask类来计算 NTP 时钟和本地时钟之间的差异。
public class offSetAsyncTask extends AsyncTask<Void,Void,Double> {
private String serverName;
private double localClockOffset;
private double destinationTimestamp;
private double roundTripDelay;
double total = 0;
Context context;
double avg;
@Override
protected Double doInBackground(Void... params) {
getAllForMe();
getAllForMe();
getAllForMe();
getAllForMe();
getAllForMe();
System.out.println("!!!!!!!" + total);
avg = total/5;
System.out.println("~~~avg. …Run Code Online (Sandbox Code Playgroud)