DownloadManagerpublic class DownloadManager extends Object
Fields Summary |
---|
private static final String | TAG | private static final boolean | DEBUG | private static final boolean | LOCAL_LOGV | private static final int | DEFERRED_MASK | public static final int | STATE_UNSTARTED | public static final int | STATE_DOWNLOADING | public static final int | STATE_TRANSIENT_FAILURE | public static final int | STATE_PERMANENT_FAILURE | private final android.content.Context | mContext | private final android.os.Handler | mHandler | private final android.content.SharedPreferences | mPreferences | private boolean | mAutoDownload | private final android.content.SharedPreferences.OnSharedPreferenceChangeListener | mPreferencesChangeListener | private final android.content.BroadcastReceiver | mRoamingStateListener | private static DownloadManager | sInstance |
Constructors Summary |
---|
private DownloadManager(android.content.Context context)
mContext = context;
mHandler = new Handler();
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
mPreferences.registerOnSharedPreferenceChangeListener(mPreferencesChangeListener);
context.registerReceiver(
mRoamingStateListener,
new IntentFilter(TelephonyIntents.ACTION_SERVICE_STATE_CHANGED));
mAutoDownload = getAutoDownloadState(mPreferences);
if (LOCAL_LOGV) {
Log.v(TAG, "mAutoDownload ------> " + mAutoDownload);
}
|
Methods Summary |
---|
static boolean | getAutoDownloadState(android.content.SharedPreferences prefs)
return getAutoDownloadState(prefs, isRoaming());
| static boolean | getAutoDownloadState(android.content.SharedPreferences prefs, boolean roaming)
boolean autoDownload = prefs.getBoolean(
MessagingPreferenceActivity.AUTO_RETRIEVAL, true);
if (LOCAL_LOGV) {
Log.v(TAG, "auto download without roaming -> " + autoDownload);
}
if (autoDownload) {
boolean alwaysAuto = prefs.getBoolean(
MessagingPreferenceActivity.RETRIEVAL_DURING_ROAMING, false);
if (LOCAL_LOGV) {
Log.v(TAG, "auto download during roaming -> " + alwaysAuto);
}
if (!roaming || alwaysAuto) {
return true;
}
}
return false;
| public static com.android.mms.util.DownloadManager | getInstance()
if (sInstance == null) {
throw new IllegalStateException("Uninitialized.");
}
return sInstance;
| private java.lang.String | getMessage(android.net.Uri uri)
NotificationInd ind = (NotificationInd) PduPersister
.getPduPersister(mContext).load(uri);
EncodedStringValue v = ind.getSubject();
String subject = (v != null) ? v.getString()
: mContext.getString(R.string.no_subject);
v = ind.getFrom();
String from = (v != null)
? ContactInfoCache.getInstance().getContactName(mContext, v.getString())
: mContext.getString(R.string.unknown_sender);
return mContext.getString(R.string.dl_failure_notification, subject, from);
| public int | getState(android.net.Uri uri)
Cursor cursor = SqliteWrapper.query(mContext, mContext.getContentResolver(),
uri, new String[] {Mms.STATUS}, null, null, null);
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
return cursor.getInt(0) &~ DEFERRED_MASK;
}
} finally {
cursor.close();
}
}
return STATE_UNSTARTED;
| public static void | init(android.content.Context context)
if (LOCAL_LOGV) {
Log.v(TAG, "DownloadManager.init()");
}
if (sInstance != null) {
Log.w(TAG, "Already initialized.");
}
sInstance = new DownloadManager(context);
| public boolean | isAuto()
return mAutoDownload;
| static boolean | isRoaming()
String roaming = SystemProperties.get(
TelephonyProperties.PROPERTY_OPERATOR_ISROAMING, null);
if (LOCAL_LOGV) {
Log.v(TAG, "roaming ------> " + roaming);
}
return "true".equals(roaming);
| public void | markState(android.net.Uri uri, int state)
// Notify user if downloading permanently failed.
if (state == STATE_PERMANENT_FAILURE) {
mHandler.post(new Runnable() {
public void run() {
try {
Toast.makeText(mContext, getMessage(uri),
Toast.LENGTH_LONG).show();
} catch (MmsException e) {
Log.e(TAG, e.getMessage(), e);
}
}
});
} else if (!mAutoDownload) {
state |= DEFERRED_MASK;
}
// Use the STATUS field to store the state of downloading process
// because it's useless for M-Notification.ind.
ContentValues values = new ContentValues(1);
values.put(Mms.STATUS, state);
SqliteWrapper.update(mContext, mContext.getContentResolver(),
uri, values, null, null);
|
|