本文整理汇总了Java中android.app.Activity.getPackageName方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.getPackageName方法的具体用法?Java Activity.getPackageName怎么用?Java Activity.getPackageName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.Activity
的用法示例。
在下文中一共展示了Activity.getPackageName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: launch
import android.app.Activity; //导入方法依赖的package包/类
@Override public void launch(Activity activity) {
RemoteViews remoteViews =
new RemoteViews(activity.getPackageName(), R.layout.notification_view);
Intent intent = new Intent(activity, SampleGridViewActivity.class);
NotificationCompat.Builder builder =
new NotificationCompat.Builder(activity).setSmallIcon(R.drawable.icon)
.setContentIntent(PendingIntent.getActivity(activity, -1, intent, 0))
.setContent(remoteViews);
Notification notification = builder.getNotification();
NotificationManager notificationManager =
(NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notification);
// Now load an image for this notification.
Picasso.with() //
.load(Data.URLS[new Random().nextInt(Data.URLS.length)]) //
.resizeDimen(R.dimen.notification_icon_width_height,
R.dimen.notification_icon_width_height) //
.into(remoteViews, R.id.photo, NOTIFICATION_ID, notification);
}
示例2: sendChooserIntent
import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
static void sendChooserIntent(boolean saveLastUsed, Activity activity,
Intent sharingIntent,
@Nullable TargetChosenCallback callback) {
synchronized (LOCK) {
if (sTargetChosenReceiveAction == null) {
sTargetChosenReceiveAction = activity.getPackageName() + "/"
+ TargetChosenReceiver.class.getName() + "_ACTION";
}
Context context = activity.getApplicationContext();
if (sLastRegisteredReceiver != null) {
context.unregisterReceiver(sLastRegisteredReceiver);
// Must cancel the callback (to satisfy guarantee that exactly one method of
// TargetChosenCallback is called).
// TODO(mgiuca): This should be called immediately upon cancelling the chooser,
// not just when the next share takes place (https://crbug.com/636274).
sLastRegisteredReceiver.cancel();
}
sLastRegisteredReceiver = new TargetChosenReceiver(saveLastUsed, callback);
context.registerReceiver(
sLastRegisteredReceiver, new IntentFilter(sTargetChosenReceiveAction));
}
Intent intent = new Intent(sTargetChosenReceiveAction);
intent.setPackage(activity.getPackageName());
intent.putExtra(EXTRA_RECEIVER_TOKEN, sLastRegisteredReceiver.hashCode());
final PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
Intent chooserIntent = Intent.createChooser(sharingIntent,
activity.getString(R.string.share_link_chooser_title),
pendingIntent.getIntentSender());
if (sFakeIntentReceiverForTesting != null) {
sFakeIntentReceiverForTesting.setIntentToSendBack(intent);
}
fireIntent(activity, chooserIntent);
}
示例3: openPlayStorePage
import android.app.Activity; //导入方法依赖的package包/类
public static void openPlayStorePage(Activity activity){
String appPackageName = activity.getPackageName();
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
示例4: initExceptionHandler
import android.app.Activity; //导入方法依赖的package包/类
public static void initExceptionHandler(Activity activity, String appName, String userName) {
final File traceFile = new File(activity.getFilesDir(), "rxtrace.log");
if (traceFile.exists()) {
try {
String trace = Utils.loadString(traceFile);
traceFile.delete();
sendTrace(activity, appName, userName, trace);
} catch (IOException e) {
e.printStackTrace();
}
}
final String packageName = activity.getPackageName();
final Thread.UncaughtExceptionHandler oldHandler =
Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable throwable) {
if (throwable != null) {
saveTrace(traceFile, throwable, packageName);
throwable.printStackTrace();
if (oldHandler!=null) {
oldHandler.uncaughtException(thread, throwable);
} else {
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
}
}
});
}
示例5: moveToForeground
import android.app.Activity; //导入方法依赖的package包/类
/**
* Move app to foreground.
*/
private void moveToForeground() {
Activity app = getActivity();
String pkgName = app.getPackageName();
Intent intent = app
.getPackageManager()
.getLaunchIntentForPackage(pkgName);
intent.addFlags( Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
app.startActivity(intent);
}
示例6: requestSystemAlertPermission
import android.app.Activity; //导入方法依赖的package包/类
/**
* @param fragment
* @param requestCode
*/
public void requestSystemAlertPermission(Activity context, Fragment fragment, int requestCode) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
return;
final String packageName = context == null ? fragment.getActivity().getPackageName() : context.getPackageName();
final Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName));
if (fragment != null)
fragment.startActivityForResult(intent, requestCode);
else
context.startActivityForResult(intent, requestCode);
}
示例7: getVersion
import android.app.Activity; //导入方法依赖的package包/类
private String getVersion() {
try {
Activity activity = getActivity();
String packageName = activity.getPackageName();
PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(packageName, 0);
//return packageInfo.versionName;
return "4.5.1";
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "getVersion: error", e);
return "1.0";
}
}
示例8: initialize
import android.app.Activity; //导入方法依赖的package包/类
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
this.filesystems = new ArrayList<Filesystem>();
this.pendingRequests = new PendingRequests();
String tempRoot = null;
String persistentRoot = null;
Activity activity = cordova.getActivity();
String packageName = activity.getPackageName();
String location = preferences.getString("androidpersistentfilelocation", "internal");
tempRoot = activity.getCacheDir().getAbsolutePath();
if ("internal".equalsIgnoreCase(location)) {
persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/";
this.configured = true;
} else if ("compatibility".equalsIgnoreCase(location)) {
/*
* Fall-back to compatibility mode -- this is the logic implemented in
* earlier versions of this plugin, and should be maintained here so
* that apps which were originally deployed with older versions of the
* plugin can continue to provide access to files stored under those
* versions.
*/
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() +
"/Android/data/" + packageName + "/cache/";
} else {
persistentRoot = "/data/data/" + packageName;
}
this.configured = true;
}
if (this.configured) {
// Create the directories if they don't exist.
File tmpRootFile = new File(tempRoot);
File persistentRootFile = new File(persistentRoot);
tmpRootFile.mkdirs();
persistentRootFile.mkdirs();
// Register initial filesystems
// Note: The temporary and persistent filesystems need to be the first two
// registered, so that they will match window.TEMPORARY and window.PERSISTENT,
// per spec.
this.registerFilesystem(new LocalFilesystem("temporary", webView.getContext(), webView.getResourceApi(), tmpRootFile));
this.registerFilesystem(new LocalFilesystem("persistent", webView.getContext(), webView.getResourceApi(), persistentRootFile));
this.registerFilesystem(new ContentFilesystem(webView.getContext(), webView.getResourceApi()));
this.registerFilesystem(new AssetFilesystem(webView.getContext().getAssets(), webView.getResourceApi()));
registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity));
// Initialize static plugin reference for deprecated getEntry method
if (filePlugin == null) {
FileUtils.filePlugin = this;
}
} else {
LOG.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)");
activity.finish();
}
}
示例9: License
import android.app.Activity; //导入方法依赖的package包/类
public License(Activity activity) {
String deviceId = Secure.getString(activity.getContentResolver(), Secure.ANDROID_ID);
licenseCallback = new BlueWatcherLicenseCheckerCallback(activity);
licenseChecker = new LicenseChecker(activity, new ServerManagedPolicy(activity, new AESObfuscator(License.SALT, activity.getPackageName(),
deviceId)), License.APP_PUBLIC_KEY);
}
示例10: getAuthority
import android.app.Activity; //导入方法依赖的package包/类
/**
* get the authority of FileProvider.
* @param activity the activity.
* @return the authority
*/
protected String getAuthority(Activity activity){
return activity.getPackageName() + ".fileprovider";
}