当前位置: 首页>>代码示例>>Java>>正文


Java Activity.sendBroadcast方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:manuelsc,项目名称:Lunary-Ethereum-Wallet,代码行数:30,代码来源:WalletStorage.java

示例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);
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:29,代码来源:Utils.java

示例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)));
}
 
开发者ID:NicoLiutong,项目名称:miaosou,代码行数:11,代码来源:SavePicture.java

示例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);
}
 
开发者ID:benlau,项目名称:androidnative.pri,代码行数:8,代码来源:ImagePicker.java

示例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();
}
 
开发者ID:JaeNuguid,项目名称:Kids-Portal-Android,代码行数:16,代码来源:helper_main.java

示例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);
    }
 
开发者ID:enricocid,项目名称:Gallery-example,代码行数:8,代码来源:SaveTools.java

示例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;
    }
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:14,代码来源:DictionarySettingsFragment.java

示例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));

	}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:61,代码来源:VolumeSettingHandler.java

示例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);
}
 
开发者ID:benlau,项目名称:androidnative.pri,代码行数:7,代码来源:VideoPicker.java


注:本文中的android.app.Activity.sendBroadcast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。