/// <summary> /// Save the current tasks to the device. /// </summary> /// <remarks> /// Example of MAM policy - allow saving to device. /// A manual check of the current MAM policy must be performed to determine whether or not saving to the device is allowed. /// NOTE: If the user's policy asks the app to encrypt files, the output of this process will also be encrypted. /// </remarks> /// <param name="doc">The formatted CSV string representation of the current tasks.</param> public void Save(string doc) { if (!MAMPolicyManager.GetPolicy(Application.Context).GetIsSaveToLocationAllowed(SaveLocation.Local, Authenticator.User)) { Toast.MakeText(Application.Context, Resource.String.err_not_allowed, ToastLength.Long).Show(); return; } // Confirm we're allowed to save to this device, ask for permission if not. ConfirmWritePermission(); // Get the default location for the export. File exportFile = new File(Android.OS.Environment.ExternalStorageDirectory, "tasks.csv"); // Now try to write the document to their device. try { PrintWriter writer = new PrintWriter(exportFile); writer.Append(doc); writer.Flush(); } catch (IOException e) { Toast.MakeText(Application.Context, e.Message, ToastLength.Long).Show(); return; } // And try to open it. Will be blocked by MAM if necessary Toast.MakeText(Application.Context, Application.Context.GetString(Resource.String.save_success, exportFile.Path), ToastLength.Short).Show(); OpenFile(exportFile); }
public override View OnMAMCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.Inflate(Resource.Layout.fragment_tasks, container, false); // Make a view adapter that will update the list as data updates TaskListAdapter adapter = new TaskListAdapter(Context); ListView displayList = rootView.FindViewById <ListView>(Resource.Id.tasks_nav_list_view); displayList.Adapter = adapter; // Example of MAM policy - allow printing. // Will be automatically blocked by MAM if necessary. rootView.FindViewById(Resource.Id.tasks_nav_print_icon).Click += (sender, e) => { if (Activity != null) { PrintHelper printer = new PrintHelper(Activity); printer.PrintTasks(); } else { Toast.MakeText(Activity, Resource.String.err_not_active, ToastLength.Long).Show(); } }; // Example of MAM policy - allow saving to device. // A manual check of the current MAM policy must be performed to determine whether or not saving to the device is allowed. // NOTE: If the user's policy asks the app to encrypt files, the output of this process will also be encrypted. rootView.FindViewById(Resource.Id.tasks_nav_save_icon).Click += (sender, e) => { if (MAMPolicyManager.GetPolicy(Activity).GetIsSaveToLocationAllowed(SaveLocation.Local, AuthManager.User)) { if (Activity != null && Context != null) { SaveHelper saveHelper = new SaveHelper(Activity, Context, TargetRequestCode); saveHelper.SaveFile(); } else { Toast.MakeText(Activity, Resource.String.err_not_active, ToastLength.Long).Show(); } } else { Toast.MakeText(Activity, Resource.String.err_not_allowed, ToastLength.Long).Show(); } }; return(rootView); }
public bool IsSaveToLocalAllowed() { return(MAMPolicyManager.GetPolicy(Forms.Context).IsSaveToPersonalAllowed); }