私は2つの活動をしていBroadcastReceiver
ます。ICS
エミュレーターの両方completeReceiver
で動作しますclickReceiver
が、私の電話でJB
は最初の1つだけが動作します。
なぜか想像もつきません。助けてくれてありがとう。
(私が試したのは、 :で変更ShareActivity.this
することでしたが、同じ結果です)。context
AlertDialog.Buider
public class ShareActivity extends Activity {
// stuff
@Override
protected void onStart() {
super.onStart();
registerReceiver(completeReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
registerReceiver(clickReceiver, new IntentFilter(DownloadManager.ACTION_NOTIFICATION_CLICKED));
Log.v(DEBUG_TAG, "_onStart");
}
// other stuff
BroadcastReceiver completeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -2);
if (enqueue != -1 && id != -2 && id == enqueue) {
Query query = new Query();
query.setFilterById(id);
dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = c.getInt(columnIndex);
if (status == DownloadManager.STATUS_SUCCESSFUL) {
AlertDialog.Builder helpBuilder = new AlertDialog.Builder(ShareActivity.this);
helpBuilder.setIcon(android.R.drawable.ic_dialog_info);
helpBuilder.setTitle(getString(R.string.information));
helpBuilder.setMessage(getString(R.string.download_complete_dialog_msg1) + titleRaw + getString(R.string.download_complete_dialog_msg2));
helpBuilder.setPositiveButton(getString(R.string.download_complete_dialog_positive), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent v_intent = new Intent();
v_intent.setAction(android.content.Intent.ACTION_VIEW);
v_intent.setDataAndType(videoUri, "video/*");
startActivity(v_intent);
}
});
helpBuilder.setNegativeButton(getString(R.string.dialogs_negative), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// cancel
}
});
AlertDialog helpDialog = helpBuilder.create();
if (! ((Activity) context).isFinishing()) {
helpDialog.show();
}
}
}
}
}
};
BroadcastReceiver clickReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
long id = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -2);
if (enqueue != -1 && id != -2 && id == enqueue) {
Query query = new Query();
query.setFilterById(id);
dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor c = dm.query(query);
if (c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
int status = c.getInt(columnIndex);
if (status == DownloadManager.STATUS_RUNNING ||
status == DownloadManager.STATUS_PAUSED ||
status == DownloadManager.STATUS_PENDING) {
AlertDialog.Builder helpBuilder = new AlertDialog.Builder(ShareActivity.this);
helpBuilder.setIcon(android.R.drawable.ic_dialog_info);
helpBuilder.setTitle(getString(R.string.cancel_download_dialog_title));
helpBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dm.remove(enqueue);
Log.d(DEBUG_TAG, "download cancelled");
}
});
helpBuilder.setNegativeButton(getString(R.string.dialogs_negative), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// cancel
}
});
AlertDialog helpDialog = helpBuilder.create();
if (! ((Activity) context).isFinishing()) {
helpDialog.show();
}
}
}
}
}
};
}