String url = "url you want to download"; DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setDescription("Some descrition"); request.setTitle("Some title"); // in order for this if to run, you must use the android 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "name-of-the-file.ext"); // get download service and enqueue file DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); manager.enqueue(request);
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); // request a window without the title dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE); return dialog; }
@Override public void watchFragments(Activity activity) { FragmentManager fragmentManager = activity.getFragmentManager(); fragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, true); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } }
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Look at this dialog!") .setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //do things } }); AlertDialog alert = builder.create(); alert.show();
DefaultRetrieverHarness() { this.parent = new android.app.Fragment(); controller.create(); controller.get().getFragmentManager().beginTransaction().add(parent, PARENT_TAG) .commitAllowingStateLoss(); controller.get().getFragmentManager().executePendingTransactions(); controller.start().resume(); }
@Override protected void onDestroy () { super.onDestroy(); }
private static boolean isActivityVisible(Activity activity) { // This is a poor heuristic, but it's about all we have. We'd rather err on the side of visible // and start requests than on the side of invisible and ignore valid requests. return !activity.isFinishing(); }
@Override public boolean hasFragmentWithTag(String tag) { return null != controller .get() .getFragmentManager() .findFragmentByTag(RequestManagerRetriever.FRAGMENT_TAG); }
@Override public void onConfigurationChanged (Configuration config) { super.onConfigurationChanged(config); boolean keyboardAvailable = false; if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) keyboardAvailable = true; input.keyboardAvailable = keyboardAvailable; }
final AlertDialog dialog = ...; editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } });
@Override public void setTheme(int resid) { // We don't want this to be called with an incompatible theme. // This could happen if you implement runtime switching of themes // using ActivityLifecycleCallbacks. if (resid != R.style.leak_canary_LeakCanary_Base) { return; } super.setTheme(resid); }
public void stopWatchingActivities() { application.unregisterActivityLifecycleCallbacks(lifecycleCallbacks); } }
@Override public boolean onKeyLongPress(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_E) { isELongPressedInAnnotatedClass = true; } return super.onKeyLongPress(keyCode, event); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }
@SuppressWarnings("deprecation") @Override public void addFragmentWithTag(String tag, RequestManager requestManager) { RequestManagerFragment fragment = new RequestManagerFragment(); fragment.setRequestManager(requestManager); controller.get().getFragmentManager().beginTransaction() .add(fragment, RequestManagerRetriever.FRAGMENT_TAG).commitAllowingStateLoss(); controller.get().getFragmentManager().executePendingTransactions(); } }
@Override protected void onDestroy () { super.onDestroy(); }
@Override public void onConfigurationChanged (Configuration config) { super.onConfigurationChanged(config); boolean keyboardAvailable = false; if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) keyboardAvailable = true; input.keyboardAvailable = keyboardAvailable; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }
@Override protected void onDestroy() { super.onDestroy(); // Robolectric does not create a new instance after Activity.recreate // we simulate the new instance by clearing our fields maintainedDependency = null; recreatedDependency = null; maintainedAbstracted = null; someObject = null; }