本文整理汇总了Java中android.content.Intent.setAction方法的典型用法代码示例。如果您正苦于以下问题:Java Intent.setAction方法的具体用法?Java Intent.setAction怎么用?Java Intent.setAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.setAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendIcon2HomeScreen
import android.content.Intent; //导入方法依赖的package包/类
public static boolean sendIcon2HomeScreen(Context context, int iconId, String appName,
String pkgName, String launcherName) {
if (context == null || iconId == 0 || TextUtils.isEmpty(appName)
|| TextUtils.isEmpty(pkgName) || TextUtils.isEmpty(launcherName)) {
return false;
}
Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
shortcutIntent.setClassName(pkgName, launcherName);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
Intent addIntent = new Intent();
addIntent.setAction(ACTION_ADD_SHORTCUT);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context, iconId));
addIntent.putExtra("duplicate", false);
context.sendBroadcast(addIntent);
return true;
}
示例2: shareText
import android.content.Intent; //导入方法依赖的package包/类
/**
* Shares the given text by encoding it as a barcode, such that another user can
* scan the text off the screen of the device.
*
* @param text the text string to encode as a barcode
* @param type type of data to encode. See {@code com.google.zxing.client.android.Contents.Type} constants.
* @return the {@link AlertDialog} that was shown to the user prompting them to download the app
* if a prompt was needed, or null otherwise
*/
public final AlertDialog shareText(CharSequence text, CharSequence type) {
Intent intent = new Intent();
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setAction(BS_PACKAGE + ".ENCODE");
intent.putExtra("ENCODE_TYPE", type);
intent.putExtra("ENCODE_DATA", text);
String targetAppPackage = findTargetAppPackage(intent);
if (targetAppPackage == null) {
return showDownloadDialog();
}
intent.setPackage(targetAppPackage);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
attachMoreExtras(intent);
if (fragment == null) {
activity.startActivity(intent);
} else {
fragment.startActivity(intent);
}
return null;
}
示例3: sendAppsQueryReply
import android.content.Intent; //导入方法依赖的package包/类
private void sendAppsQueryReply(Context context) {
Intent mReply = new Intent();
mReply.setAction(SnachExtras.INTENT_ACTION_SUPPORTED_APPS_REPLY);
mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_NAME, context.getResources().getString(R.string.stnd_stopwatch_apptitle));
mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_PACKAGE, context.getPackageName());
mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_DESCRIPTION, context.getResources().getString(R.string.stnd_stopwatch_description));
/*
DEPRECATED, used when the app is selected:
Usually the app itself should be started and show the user which features will be added to his Snach.
This is useful to let the user select functions he needs and even to let him customize the layout,
but its a safety lack.
This feature can be easily implemented later, so for now if an app has two Snach Apps it has to send
two of these BroadcastIntents back as a reply.
*/
mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_INTENT_EXTRA, "myCustomIntentExtra");
// Intents used on screen reauests and interactions:
mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_BC_ACTION, "com.assembtec.snach.STND_STOPWATCH");
mReply.putExtra(SnachExtras.INTENT_EXTRA_APP_BC_EXTRA, "mCustomBroadcastExtra");
context.sendBroadcast(mReply);
}
示例4: send
import android.content.Intent; //导入方法依赖的package包/类
public void send(Context context) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, content.toString());
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, context.getResources().getText(R.string.share)));
}
示例5: autoSync
import android.content.Intent; //导入方法依赖的package包/类
private void autoSync() {
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG);
/* Skip sync if there are no repos. */
if (getAllRepos().size() == 0) {
return;
}
Intent intent = new Intent(mContext, SyncService.class);
intent.setAction(AppIntent.ACTION_SYNC_START);
intent.putExtra(AppIntent.EXTRA_IS_AUTOMATIC, true);
mContext.startService(intent);
}
示例6: startPollingService
import android.content.Intent; //导入方法依赖的package包/类
/**
* 开启轮询服务
*/
@TargetApi(Build.VERSION_CODES.CUPCAKE)
public static void startPollingService(Context context, int mills, Class<?> cls, String action) {
Intent intent = new Intent(context, cls);
intent.setAction(action);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
startPolling(context, mills, pendingIntent);
}
示例7: getInstallApkIntent
import android.content.Intent; //导入方法依赖的package包/类
public static Intent getInstallApkIntent(File file)
{
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
return intent;
}
示例8: stopPlayback
import android.content.Intent; //导入方法依赖的package包/类
private void stopPlayback() {
// reset metadata
mStationMetadata = null;
// rotate_infinite playback button
changeVisualState(mActivity);
// stop player service using intent
Intent intent = new Intent(mActivity, PlayerService.class);
intent.setAction(TransistorKeys.ACTION_STOP);
mActivity.startService(intent);
LogHelper.v(LOG_TAG, "Stopping player service.");
}
示例9: releaseWakeLock
import android.content.Intent; //导入方法依赖的package包/类
public static void releaseWakeLock(Context context, int wakeLockId) {
Timber.v("CoreReceiver Got request to release wakeLock %d", wakeLockId);
Intent i = new Intent();
i.setClass(context, CoreReceiver.class);
i.setAction(WAKE_LOCK_RELEASE);
i.putExtra(WAKE_LOCK_ID, wakeLockId);
context.sendBroadcast(i);
}
示例10: onItemClick
import android.content.Intent; //导入方法依赖的package包/类
/**
* Callback method to be invoked when an item in this AdapterView has
* been clicked.
* <p>
* Implementers can call getItemAtPosition(position) if they need
* to access the data associated with the selected item.
*
* @param parent The AdapterView where the click happened.
* @param view The view within the AdapterView that was clicked (this
* will be a view provided by the adapter)
* @param position The position of the view in the adapter.
* @param id The row id of the item that was clicked.
*/
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ItemLabel item = (ItemLabel) listView.getItemAtPosition(position);
Uri imageUri = getImageUri(item.getImage());
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, String.format(
"Hey, look at my %s", item.getName()));
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, "Share"));
}
示例11: notifyImpl
import android.content.Intent; //导入方法依赖的package包/类
private void notifyImpl(Context context, OwnerInfo info){
String ownerName = fromId > 0 ? (stringEmptyIfNull(firstName) + " " + stringEmptyIfNull(lastName)) : groupName;
final NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Utils.hasOreo()){
nManager.createNotificationChannel(AppNotificationChannels.getNewPostChannel(context));
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, AppNotificationChannels.NEW_POST_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notify_statusbar)
.setLargeIcon(info.getAvatar())
.setContentTitle(context.getString(R.string.new_post_title))
.setContentText(context.getString(R.string.new_post_was_published_in, ownerName))
.setStyle(new NotificationCompat.BigTextStyle().bigText(text))
.setAutoCancel(true);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(Extra.PLACE, PlaceFactory.getPostPreviewPlace(accountId, postId, fromId));
intent.setAction(MainActivity.ACTION_OPEN_PLACE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, fromId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
builder.setContentIntent(contentIntent);
Notification notification = builder.build();
configOtherPushNotification(notification);
nManager.notify(String.valueOf(fromId), NotificationHelper.NOTIFICATION_NEW_POSTS_ID, notification);
}
示例12: onOptionsItemSelected
import android.content.Intent; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_join:
FavouriteJourneysActivity.this.startActivity(new Intent(FavouriteJourneysActivity.this, LicenseUpgradeActivity.class));
return true;
case R.id.action_settings:
FavouriteJourneysActivity.this.startActivity(new Intent(FavouriteJourneysActivity.this, SettingsActivity.class));
return true;
case R.id.action_share:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
"Dai un'occhiata a quest'app pensata appositamente per i pendolari Trenitalia!\nhttps://play.google.com/store/apps/details?id=com.jaus.albertogiunta.justintrain_oraritreni");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Consiglia l'app via..."));
return true;
case R.id.action_review:
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + getPackageName())));
}
return true;
case R.id.action_legend:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(FavouriteJourneysActivity.this);
View view = LayoutInflater.from(FavouriteJourneysActivity.this).inflate(R.layout.dialog_legend, null);
alertDialog.setView(view)
.setPositiveButton("OK", (dialogInterface, i) -> dialogInterface.dismiss())
.create()
.show();
return true;
case R.id.action_about:
FavouriteJourneysActivity.this.startActivity(new Intent(FavouriteJourneysActivity.this, AboutActivity.class));
return true;
case R.id.label_pro:
AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(FavouriteJourneysActivity.this);
View view2 = LayoutInflater.from(FavouriteJourneysActivity.this).inflate(R.layout.dialog_pro_legend, null);
alertDialog2.setView(view2)
.setPositiveButton("OK", (dialogInterface, i) -> dialogInterface.dismiss())
.create()
.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
示例13: onNavigationItemSelected
import android.content.Intent; //导入方法依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.db) {
startActivity(new Intent(getApplicationContext(), Dashboard.class));
// Handle the camera action
} else if (id == R.id.ml) {
startActivity(new Intent(getApplicationContext(), MyLocation.class));
}
else if (id == R.id.atk) {
startActivity(new Intent(getApplicationContext(), TrackerActivity.class));
}else if (id == R.id.tk) {
startActivity(new Intent(getApplicationContext(),trackedusers.class));
} else if (id == R.id.sr) {
startActivity(new Intent(getApplicationContext(),ShortestDistance.class));
} else if (id == R.id.nt) {
startActivity(new Intent(getApplicationContext(), MyNotes1.class));
} else if (id == R.id.ec) {
startActivity(new Intent(getApplicationContext(), Navigation.class));
}
else if (id == R.id.el) {
}
else if (id == R.id.lg) {
AuthUI.getInstance()
.signOut(Dashboard.this)
.addOnCompleteListener(new OnCompleteListener<Void>() {
public void onComplete(@NonNull Task<Void> task) {
// user is now signed out
startActivity(new Intent(Dashboard.this, Login.class));
finish();
}
}); }
else if (id == R.id.nav_share) {
Intent sh=new Intent();
sh.setAction(Intent.ACTION_SEND);
sh.putExtra(Intent.EXTRA_TEXT,"Download iSPY from here -> www.iSPY.com");
sh.setType("text/plain");
startActivity(sh);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例14: asyncNext
import android.content.Intent; //导入方法依赖的package包/类
/**
* Changes to the next track asynchronously
*/
public static void asyncNext(final Context context) {
final Intent previous = new Intent(context, MusicService.class);
previous.setAction(MusicServiceConstants.NEXT_ACTION);
context.startService(previous);
}
示例15: getPackageNameToUse
import android.content.Intent; //导入方法依赖的package包/类
/**
* Goes through all apps that handle VIEW intents and have a warmup service. Picks
* the one chosen by the user if there is one, otherwise makes a best effort to return a
* valid package name.
*
* This is <strong>not</strong> threadsafe.
*
* @param context {@link Context} to use for accessing {@link PackageManager}.
* @return The package name recommended to use for connecting to custom tabs related components.
*/
public static String getPackageNameToUse(Context context) {
if (sPackageNameToUse != null) return sPackageNameToUse;
PackageManager pm = context.getPackageManager();
// Get default VIEW intent handler.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0);
String defaultViewHandlerPackageName = null;
if (defaultViewHandlerInfo != null) {
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName;
}
// Get all apps that can handle VIEW intents.
List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
List<String> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
Intent serviceIntent = new Intent();
serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
serviceIntent.setPackage(info.activityInfo.packageName);
if (pm.resolveService(serviceIntent, 0) != null) {
packagesSupportingCustomTabs.add(info.activityInfo.packageName);
}
}
// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents
// and service calls.
if (packagesSupportingCustomTabs.isEmpty()) {
sPackageNameToUse = null;
} else if (packagesSupportingCustomTabs.size() == 1) {
sPackageNameToUse = packagesSupportingCustomTabs.get(0);
} else if (!TextUtils.isEmpty(defaultViewHandlerPackageName)
&& !hasSpecializedHandlerIntents(context, activityIntent)
&& packagesSupportingCustomTabs.contains(defaultViewHandlerPackageName)) {
sPackageNameToUse = defaultViewHandlerPackageName;
} else if (packagesSupportingCustomTabs.contains(STABLE_PACKAGE)) {
sPackageNameToUse = STABLE_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(BETA_PACKAGE)) {
sPackageNameToUse = BETA_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(DEV_PACKAGE)) {
sPackageNameToUse = DEV_PACKAGE;
} else if (packagesSupportingCustomTabs.contains(LOCAL_PACKAGE)) {
sPackageNameToUse = LOCAL_PACKAGE;
}
return sPackageNameToUse;
}