編輯:關於Android編程
通知媒體庫更新
糾結了幾天,百度到一個方法,可以在安卓4.4,通知媒體庫更新。package com.iwanghang.drmplayer; import android.app.AlertDialog; import android.app.Dialog; import android.content.BroadcastReceiver; import android.content.Intent; import android.content.IntentFilter; import android.database.Cursor; import android.graphics.Path; import android.media.MediaScannerConnection; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; import android.support.v4.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Toast; import com.iwanghang.drmplayer.utils.Constant; import com.iwanghang.drmplayer.utils.DownloadUtils; import com.iwanghang.drmplayer.utils.MediaScanner; import com.iwanghang.drmplayer.utils.MediaUtils; import com.iwanghang.drmplayer.utils.SearchMusicUtils; import com.iwanghang.drmplayer.vo.SearchResult; import java.io.File; import java.io.IOException; import java.util.ArrayList; /** * Created by iwanghang on 16/5/3. * DownloadDialogFargment */ public class DownloadDialogFragment extends DialogFragment { private SearchResult searchResult;//當前要下載的歌曲對象 private MainActivity mainActivity; public static DownloadDialogFragment newInstance(SearchResult searchResult){ DownloadDialogFragment downloadDialogFragment = new DownloadDialogFragment(); downloadDialogFragment.searchResult = searchResult; return downloadDialogFragment; } private String[] items; @Override public void onAttach(Context context) { super.onAttach(context); mainActivity = (MainActivity) getActivity(); //items = new String[]{"下載","取消"}; items = new String[]{getString(R.string.download),getString(R.string.cancel)}; } //創建對話框的事件方法 @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(mainActivity); builder.setCancelable(true);//返回鍵可以取消 builder.setItems(items,new DialogInterface.OnClickListener(){ @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: //執行下載 downloadMusic(); break; case 1://取消 dialog.dismiss(); break; } } }); return builder.show(); } //下載音樂 private void downloadMusic() { Toast.makeText(mainActivity, "正在下載:" + searchResult.getMusicName(), Toast.LENGTH_LONG).show(); DownloadUtils.getsInstance().setListener(new DownloadUtils.OnDownloadListener() { @Override public void onDowload(String mp3Url) { //下載成功 Toast.makeText(mainActivity, "下載成功", Toast.LENGTH_SHORT).show(); System.out.println("DownloadDialogFragment.downloadMusic @ = " + Environment.getExternalStorageDirectory()+Constant.DIR_MUSIC + "/" + mp3Url); //更新媒體庫 scanFile(mainActivity,Environment.getExternalStorageDirectory()+Constant.DIR_MUSIC + "/" + mp3Url); //更新 本地音樂列表 } @Override public void onFailed(String error) { //下載失敗 Toast.makeText(mainActivity, error, Toast.LENGTH_SHORT).show(); } }).download(searchResult); } //更新媒體庫 /** * 通知媒體庫更新文件 * @param context * @param filePath 文件全路徑 * * */ public void scanFile(Context context, String filePath) { Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); scanIntent.setData(Uri.fromFile(new File(filePath))); context.sendBroadcast(scanIntent); } }
推送現在在移動項目開發中已經很常見了,比較常見的推送方式有小米推送、極光推送和個推,今天我們所講解的是Tencent的信鴿推送在Android上的應用。一、信鴿Andro
Notification是顯示在手機狀態欄的通知,Notification通知是具有全局性的通知,一般通過NotificationManager來進行管理.一般運用Not
一、基礎知識1.Android 進程優先級1.1 進程優先級等級一般分法:- Activte process- Visible Process- Service proc
前面walfred已經介紹了使用apktool對apk進行逆向編譯,通過apktool我們的確可以反編譯已經序列化後的AndroidManifest.xml和資源文件等等