本文整理汇总了Java中android.app.Activity.sendBroadcast方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.sendBroadcast方法的具体用法?Java Activity.sendBroadcast怎么用?Java Activity.sendBroadcast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Activity
的用法示例。
在下文中一共展示了Activity.sendBroadcast方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportWallet
import android.app.Activity; //导入方法依赖的package包/类
private boolean exportWallet(Activity c, boolean already) {
if (walletToExport == null) return false;
if (walletToExport.startsWith("0x"))
walletToExport = walletToExport.substring(2);
if (ExternalStorageHandler.hasPermission(c)) {
File folder = new File(Environment.getExternalStorageDirectory(), "Lunary");
if (!folder.exists()) folder.mkdirs();
File storeFile = new File(folder, walletToExport + ".json");
try {
copyFile(new File(c.getFilesDir(), walletToExport), storeFile);
} catch (IOException e) {
return false;
}
// fix, otherwise won't show up via USB
Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri fileContentUri = Uri.fromFile(storeFile); // With 'permFile' being the File object
mediaScannerIntent.setData(fileContentUri);
c.sendBroadcast(mediaScannerIntent); // With 'this' being the context, e.g. the activity
return true;
} else if (!already) {
ExternalStorageHandler.askForPermission(c);
return exportWallet(c, true);
} else {
return false;
}
}
示例2: createShortcut
import android.app.Activity; //导入方法依赖的package包/类
/**
* Creates a shortcut on the homescreen using the
* {@link HistoryItem} information that opens the
* browser. The icon, URL, and title are used in
* the creation of the shortcut.
*
* @param activity the activity needed to create
* the intent and show a snackbar message
* @param item the HistoryItem to create the shortcut from
*/
public static void createShortcut(@NonNull Activity activity, @NonNull HistoryItem item) {
if (TextUtils.isEmpty(item.getUrl())) {
return;
}
Log.d(TAG, "Creating shortcut: " + item.getTitle() + ' ' + item.getUrl());
Intent shortcutIntent = new Intent(activity, MainActivity.class);
shortcutIntent.setData(Uri.parse(item.getUrl()));
final String title = TextUtils.isEmpty(item.getTitle()) ? activity.getString(R.string.untitled) : item.getTitle();
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, item.getBitmap());
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
activity.sendBroadcast(addIntent);
Utils.showSnackbar(activity, R.string.message_added_to_homescreen);
}
示例3: saveToContentProvider
import android.app.Activity; //导入方法依赖的package包/类
private static void saveToContentProvider(File file,Activity activity){
// 其次把文件插入到系统图库
try {
MediaStore.Images.Media.insertImage(activity.getContentResolver(), file.getAbsolutePath(),file.getName(), null);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// 最后通知图库更新
activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
}
示例4: broadcastToMediaScanner
import android.app.Activity; //导入方法依赖的package包/类
private static void broadcastToMediaScanner(Uri uri) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(uri);
Activity activity = org.qtproject.qt5.android.QtNative.activity();
activity.sendBroadcast(mediaScanIntent);
}
示例5: installShortcut
import android.app.Activity; //导入方法依赖的package包/类
public static void installShortcut (Activity activity, String title, String url, View view) {
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setClassName(activity, "jae.KidsPortal.Browser.Activity_Main");
i.setData(Uri.parse(url));
Intent shortcut = new Intent();
shortcut.putExtra("android.intent.extra.shortcut.INTENT", i);
shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN");
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(activity.getApplicationContext(), R.mipmap.ic_launcher));
shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
activity.sendBroadcast(shortcut);
Snackbar.make(view, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show();
}
示例6: notifyChange
import android.app.Activity; //导入方法依赖的package包/类
private static void notifyChange(File f, Activity activity) {
Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri fileContentUri = Uri.fromFile(f);
mediaScannerIntent.setData(fileContentUri);
activity.sendBroadcast(mediaScannerIntent);
}
示例7: onPause
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void onPause() {
super.onPause();
final Activity activity = getActivity();
UpdateHandler.unregisterUpdateEventListener(this);
activity.unregisterReceiver(mConnectivityChangedReceiver);
if (mChangedSettings) {
final Intent newDictBroadcast =
new Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION);
activity.sendBroadcast(newDictBroadcast);
mChangedSettings = false;
}
}
示例8: onClick
import android.app.Activity; //导入方法依赖的package包/类
public void onClick(DialogInterface dialog, int whichButton) {
if (BUTTON_CANCEL == whichButton) {
return; // stop on cancel
}
Activity activity = mActivity;
// cache
final AudioManager manager = (AudioManager) activity.getSystemService(Activity.AUDIO_SERVICE);
final int[] volumes = mVolumes;
final SeekBar[] seekBars = mSeekBars;
final int[] streamTypes = STREAM_TYPES;
// apply changes
final int length = seekBars.length;
boolean prevChanged = false;
for (int i = 0; i<length; i++) {
// get control
int value = seekBars[i].getProgress();
boolean isNotification = i == 1;
boolean changed = value != volumes[i]
|| (isNotification && prevChanged);
if (changed) {
manager.setStreamVolume(streamTypes[i], value, 0);
//Log.d(TAG, "updating index: " + i + ", value: " + value);
}
if (isNotification) {
// if notification change updated volume as well we should return volume back (2.0 behavior)
int ringerVolumeDesired = seekBars[0].getProgress();
int ringerVolumeActual = manager.getStreamVolume(streamTypes[0]);
if (ringerVolumeDesired != ringerVolumeActual) {
manager.setStreamVolume(streamTypes[0], ringerVolumeDesired, 0);
//Log.d(TAG, "changing ringer volume to desired value: " + + value);
}
}
prevChanged = changed;
}
// check if we have to switch silent / not silen mode
int ringerVolume = manager.getStreamVolume(AudioManager.STREAM_RING);
int notifVolume = manager.getStreamVolume(AudioManager.STREAM_NOTIFICATION);
int ringerMode = manager.getRingerMode();
if (ringerVolume > 0 && ringerMode == AudioManager.RINGER_MODE_SILENT) {
Toast.makeText(activity, activity.getString(R.string.msg_not_silent_warning, ringerVolume), Toast.LENGTH_LONG).show();
} else if (ringerVolume == 0 && ringerMode == AudioManager.RINGER_MODE_NORMAL) {
Toast.makeText(activity, R.string.msg_zero_ringer_warning, Toast.LENGTH_LONG).show();
} else if (notifVolume == 0 && ringerMode == AudioManager.RINGER_MODE_NORMAL) {
Toast.makeText(activity, R.string.msg_zero_notification_warning, Toast.LENGTH_LONG).show();
}
// send internal volume changed notification
activity.sendBroadcast(new Intent(Constants.ACTION_VOLUME_UPDATED));
}
示例9: broadcastToMediaScanner
import android.app.Activity; //导入方法依赖的package包/类
private static void broadcastToMediaScanner(Uri uri) {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(uri);
Activity activity = org.qtproject.qt5.android.QtNative.activity();
activity.sendBroadcast(mediaScanIntent);
}