本文整理汇总了Java中android.content.Intent.setTypeAndNormalize方法的典型用法代码示例。如果您正苦于以下问题:Java Intent.setTypeAndNormalize方法的具体用法?Java Intent.setTypeAndNormalize怎么用?Java Intent.setTypeAndNormalize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.setTypeAndNormalize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: share
import android.content.Intent; //导入方法依赖的package包/类
/**
* Open a chooser dialog to send text content to other apps.
*
* Refer http://developer.android.com/intl/ko/training/sharing/send.html
*
* @param content the data to send
* @param dialogTitle the title of the chooser dialog
*/
@ReactMethod
public void share(ReadableMap content, String dialogTitle, Promise promise) {
if (content == null) {
promise.reject(ERROR_INVALID_CONTENT, "Content cannot be null");
return;
}
try {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setTypeAndNormalize("text/plain");
if (content.hasKey("title")) {
intent.putExtra(Intent.EXTRA_SUBJECT, content.getString("title"));
}
if (content.hasKey("message")) {
intent.putExtra(Intent.EXTRA_TEXT, content.getString("message"));
}
Intent chooser = Intent.createChooser(intent, dialogTitle);
chooser.addCategory(Intent.CATEGORY_DEFAULT);
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
currentActivity.startActivity(chooser);
} else {
getReactApplicationContext().startActivity(chooser);
}
WritableMap result = Arguments.createMap();
result.putString("action", ACTION_SHARED);
promise.resolve(result);
} catch (Exception e) {
promise.reject(ERROR_UNABLE_TO_OPEN_DIALOG, "Failed to open share dialog");
}
}