本文整理汇总了C#中Android.Content.Context.SendBroadcast方法的典型用法代码示例。如果您正苦于以下问题:C# Context.SendBroadcast方法的具体用法?C# Context.SendBroadcast怎么用?C# Context.SendBroadcast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Content.Context
的用法示例。
在下文中一共展示了Context.SendBroadcast方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendBroadcastForToastMessage
public static void SendBroadcastForToastMessage(Context context, string messageToToast)
{
var toastIntent = new Intent(AppConstants.APPLICATION_COMMAND);
toastIntent.PutExtra(AppConstants.COMMAND_TYPE_ID, (int)AppConstants.ApplicationCommandType.ShowToastMessage);
toastIntent.PutExtra(AppConstants.TOAST_MESSAGE_KEY, messageToToast);
context.SendBroadcast(toastIntent);
}
示例2: AddFileToGallery
public static void AddFileToGallery(Context context, string filePath)
{
Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
File file = new File(filePath);
var contentUri = Uri.FromFile(file);
mediaScanIntent.SetData(contentUri);
context.SendBroadcast(mediaScanIntent);
}
示例3: OnReceive
public override void OnReceive(Context context, Intent intent)
{
//There's no point in going any further if the service isn't running.
if (!App.Current.AudioServiceConnection.IsPlayerBound) return;
//Aaaaand there's no point in continuing if the intent doesn't contain info about headset control inputs.
var intentAction = intent.Action;
if (!Intent.ActionMediaButton.Equals(intentAction))
{
return;
}
var keyEvent = (KeyEvent) intent.GetParcelableExtra(Intent.ExtraKeyEvent);
if (keyEvent.Action != KeyEventActions.Down) return;
var keycode = keyEvent.KeyCode;
//Switch through each event and perform the appropriate action based on the intent that's ben
if (keycode == Keycode.MediaPlayPause || keycode == Keycode.Headsethook)
{
//Toggle play/pause.
var playPauseIntent = new Intent();
playPauseIntent.SetAction(AudioPlaybackService.PlayPauseAction);
context.SendBroadcast(playPauseIntent);
}
if (keycode == Keycode.MediaNext)
{
//Fire a broadcast that skips to the next track.
var nextIntent = new Intent();
nextIntent.SetAction(AudioPlaybackService.NextAction);
context.SendBroadcast(nextIntent);
}
if (keycode == Keycode.MediaPrevious)
{
//Fire a broadcast that goes back to the previous track.
var previousIntent = new Intent();
previousIntent.SetAction(AudioPlaybackService.PrevAction);
context.SendBroadcast(previousIntent);
}
}
示例4: RefreshWidget
/**
* Sends a request to the rich push message to refresh with a delay
* @param context Application context
* @param delayInMs Delay to wait in milliseconds before sending the request
*/
public static void RefreshWidget(Context context, long delayInMs) {
Intent refreshIntent = new Intent(context, typeof (RichPushWidgetProvider));
refreshIntent.SetAction (RichPushWidgetProvider.REFRESH_ACTION);
if (delayInMs > 0) {
PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, 0, refreshIntent, 0);
AlarmManager am = (AlarmManager) context.GetSystemService(Context.AlarmService);
am.Set (AlarmType.RtcWakeup, (long) new TimeSpan (DateTime.Now.Ticks).TotalMilliseconds + delayInMs, pendingIntent);
} else {
context.SendBroadcast(refreshIntent);
}
}
示例5: RefreshWidget
/**
* Sends a request to the rich push message to refresh with a delay
* @param context Application context
* @param delayInMs Delay to wait in milliseconds before sending the request
*/
public static void RefreshWidget(Context context, long delayInMs) {
Intent refreshIntent = new Intent(context, typeof (RichPushWidgetProvider));
refreshIntent.SetAction (RichPushWidgetProvider.REFRESH_ACTION);
if (delayInMs > 0) {
PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, 0, refreshIntent, 0);
AlarmManager am = (AlarmManager) context.GetSystemService(Context.AlarmService);
am.Set (AlarmType.RtcWakeup, Java.Lang.JavaSystem.CurrentTimeMillis() + delayInMs, pendingIntent);
} else {
context.SendBroadcast(refreshIntent);
}
}
示例6: TriggerRequest
public static void TriggerRequest(Context ctx, string pkgName, PluginDatabase pluginDatabase)
{
try
{
Intent triggerIntent = new Intent(Strings.ActionTriggerRequestAccess);
triggerIntent.SetPackage(pkgName);
triggerIntent.PutExtra(Strings.ExtraSender, ctx.PackageName);
string requestToken = pluginDatabase.GetRequestToken(pkgName);
triggerIntent.PutExtra(Strings.ExtraRequestToken, requestToken);
Android.Util.Log.Debug(_tag, "Request token: " + requestToken);
ctx.SendBroadcast(triggerIntent);
}
catch (Exception e)
{
}
}
示例7: OnReceive
public override void OnReceive(Context context, Intent intent)
{
PluginDatabase pluginDb = new PluginDatabase(context);
if (intent.Action == Strings.ActionRequestAccess)
{
var senderPackage = intent.GetStringExtra(Strings.ExtraSender);
var requestToken = intent.GetStringExtra(Strings.ExtraRequestToken);
var requestedScopes = intent.GetStringArrayListExtra(Strings.ExtraScopes);
if (!AreScopesValid(requestedScopes))
{
return;
}
if (pluginDb.GetRequestToken(senderPackage) != requestToken)
{
Log.Warn(_tag, "Invalid requestToken!");
return;
}
string currentAccessToken = pluginDb.GetAccessToken(senderPackage);
if ((currentAccessToken != null)
&& (AccessManager.IsSubset(requestedScopes,
pluginDb.GetPluginScopes(senderPackage))))
{
//permission already there.
var i = new Intent(Strings.ActionReceiveAccess);
i.PutExtra(Strings.ExtraSender, context.PackageName);
i.PutExtra(Strings.ExtraAccessToken, currentAccessToken);
//TODO: Plugin should verify requestToken to make sure it doesn't receive accessTokens from malicious apps
i.PutExtra(Strings.ExtraRequestToken, requestToken);
i.SetPackage(senderPackage);
context.SendBroadcast(i);
Log.Debug(_tag, "Plugin " + senderPackage + " enabled.");
}
else
{
//store that scope was requested but not yet approved (=> accessToken = null)
pluginDb.StorePlugin(senderPackage, null, requestedScopes);
Log.Debug(_tag, "Plugin " + senderPackage + " not enabled.");
//see if the plugin has an access token
string accessToken = intent.GetStringExtra(Strings.ExtraAccessToken);
if (accessToken != null)
{
//notify plugin that access token is no longer valid or sufficient
Intent i = new Intent(Strings.ActionRevokeAccess);
i.PutExtra(Strings.ExtraSender, context.PackageName);
i.PutExtra(Strings.ExtraAccessToken, accessToken);
i.SetPackage(senderPackage);
context.SendBroadcast(i);
Log.Warn(_tag, "Access token of plugin " + senderPackage + " not (or no more) valid.");
}
}
if (OnReceivedRequest != null)
OnReceivedRequest(this, new PluginHostEventArgs() { Package = senderPackage });
}
}
示例8: OnReceive
public override void OnReceive(Context context, Intent intent)
{
String action = intent.Action;
//check if we have a last opened entry
//this should always be non-null, but if the OS has killed the app, it might occur.
if (App.Kp2a.GetDb().LastOpenedEntry == null)
{
Intent i = new Intent(context, typeof(AppKilledInfo));
i.SetFlags(ActivityFlags.ClearTask | ActivityFlags.NewTask);
context.StartActivity(i);
return;
}
if (action.Equals(Intents.CopyUsername))
{
String username = App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.ReadSafe(PwDefs.UserNameField);
if (username.Length > 0)
{
CopyToClipboardService.CopyValueToClipboardWithTimeout(context, username);
}
context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer
}
else if (action.Equals(Intents.CopyPassword))
{
String password = App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.ReadSafe(PwDefs.PasswordField);
if (password.Length > 0)
{
CopyToClipboardService.CopyValueToClipboardWithTimeout(context, password);
}
context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer
}
else if (action.Equals(Intents.CheckKeyboard))
{
CopyToClipboardService.ActivateKeyboard(context);
}
}
示例9: RefreshWidget
public static void RefreshWidget (Context ctx, string action, long delayInMs)
{
//Sends a request to the rich push message to refresh with a delay.
var refreshIntent = new Intent (ctx, typeof (WidgetProvider));
refreshIntent.SetAction (action);
if (delayInMs > 0) {
PendingIntent pendingIntent = PendingIntent.GetBroadcast (ctx, 0, refreshIntent, 0);
var am = (AlarmManager) ctx.GetSystemService (Context.AlarmService);
am.Set (AlarmType.RtcWakeup, (long) new TimeSpan (DateTime.Now.Ticks).TotalMilliseconds + delayInMs, pendingIntent);
} else {
ctx.SendBroadcast (refreshIntent);
}
}
示例10: TriggerRequest
public static void TriggerRequest(Context ctx, string pkgName, PluginDatabase pluginDatabase)
{
try
{
Intent triggerIntent = new Intent(Strings.ActionTriggerRequestAccess);
triggerIntent.SetPackage(pkgName);
triggerIntent.PutExtra(Strings.ExtraSender, ctx.PackageName);
triggerIntent.PutExtra(Strings.ExtraRequestToken, pluginDatabase.GetRequestToken(pkgName));
ctx.SendBroadcast(triggerIntent);
}
catch (Exception e)
{
}
}