當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。