本文整理汇总了Java中com.unity3d.player.UnityPlayer.currentActivity方法的典型用法代码示例。如果您正苦于以下问题:Java UnityPlayer.currentActivity方法的具体用法?Java UnityPlayer.currentActivity怎么用?Java UnityPlayer.currentActivity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.unity3d.player.UnityPlayer
的用法示例。
在下文中一共展示了UnityPlayer.currentActivity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openAppSettings
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
/**
* Open app notification settings
*/
public static void openAppSettings(){
Activity activity = UnityPlayer.currentActivity;
Intent intent = new Intent();
intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
//for Android 5-7
intent.putExtra("app_package", activity.getPackageName());
intent.putExtra("app_uid", activity.getApplicationInfo().uid);
// for Android O
intent.putExtra("android.provider.extra.APP_PACKAGE", activity.getPackageName());
activity.startActivity(intent);
}
示例2: setLocalNotification
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
/**
* ローカル通知をセットする
* @param notificationId 通知ID
* @param title 通知タイトル
* @param message 通知メッセージ
* @param sentAt 何秒後に通知するか
* @param isUnique 通知を重複させないか
*/
public static void setLocalNotification(int notificationId, String title, String message, int sentAt, boolean isUnique) {
// Delete duplicate notification
if (isUnique)
cancelLocalNotification(notificationId);
// Create intent
Activity activity = UnityPlayer.currentActivity;
Context context = activity.getApplicationContext();
Intent intent = new Intent(context, NotificationReceiver.class);
// Set intent params
intent.putExtra(LocalNotificationConstants.INTENT_ID_KEY, notificationId);
intent.putExtra(LocalNotificationConstants.INTENT_TITLE_KEY, title);
intent.putExtra(LocalNotificationConstants.INTENT_MESSAGE_KEY, message);
intent.putExtra(LocalNotificationConstants.INTENT_ACTION_KEY, UnityPlayerActivity.class.getName());
// Set notification time
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, sentAt);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
示例3: Share
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
static void Share(final String title, final String text, final int withImage) throws IOException
{
if (Build.VERSION.SDK_INT >= 23 && withImage != 0)
{
new PermissionRequester(UnityPlayer.currentActivity, new PermissionListener() {
@Override
public void onComplete(boolean status)
{
try
{
if (status)
ShareWoRequestPermissions(title, text, withImage);
} catch (IOException e)
{
e.printStackTrace();
}
}
});
}
else
ShareWoRequestPermissions(title, text, withImage);
}
示例4: notify
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public static void notify(String title, String body) {
Activity activity = UnityPlayer.currentActivity;
Context context = activity.getApplicationContext();
int id =(int)(Math.random() * 10000.0f) + 1;
Intent intent2 = new Intent();
intent2.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent2,
PendingIntent.FLAG_UPDATE_CURRENT);
final PackageManager pm=context.getPackageManager();
ApplicationInfo applicationInfo = null;
try {
applicationInfo = pm.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return;
}
final int appIconResId = applicationInfo.icon;
Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), appIconResId);
// NotificationBuilderを作成
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentIntent(contentIntent);
builder.setTicker(title);
builder.setSmallIcon(appIconResId);
builder.setContentTitle(title);
builder.setContentText(body);
builder.setLargeIcon(largeIcon);
builder.setWhen(System.currentTimeMillis());
builder.setDefaults(Notification.DEFAULT_SOUND
| Notification.DEFAULT_VIBRATE
| Notification.DEFAULT_LIGHTS);
builder.setAutoCancel(true);
NotificationManager manager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(id, builder.build());
}
示例5: SetRepeatingNotification
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public static void SetRepeatingNotification(int id, long delayMs, String title, String message, String ticker, long rep, int sound, String soundName, int vibrate, int lights,
String largeIconResource, String smallIconResource, int bgColor, String bundle, String channel, ArrayList<NotificationAction> actions)
{
Activity currentActivity = UnityPlayer.currentActivity;
AlarmManager am = (AlarmManager)currentActivity.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(currentActivity, UnityNotificationManager.class);
intent.putExtra("ticker", ticker);
intent.putExtra("title", title);
intent.putExtra("message", message);
intent.putExtra("id", id);
intent.putExtra("color", bgColor);
intent.putExtra("sound", sound == 1);
intent.putExtra("soundName", soundName);
intent.putExtra("vibrate", vibrate == 1);
intent.putExtra("lights", lights == 1);
intent.putExtra("l_icon", largeIconResource);
intent.putExtra("s_icon", smallIconResource);
intent.putExtra("bundle", bundle);
intent.putExtra("channel", channel);
Bundle b = new Bundle();
b.putParcelableArrayList("actions", actions);
intent.putExtra("actionsBundle", b);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + delayMs, rep, PendingIntent.getBroadcast(currentActivity, id, intent, 0));
}
示例6: countryCodeFromLastKnownLocation
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public static String countryCodeFromLastKnownLocation() throws IOException {
Activity current = UnityPlayer.currentActivity;
LocationManager locationManager =
(LocationManager) current.getSystemService(Context.LOCATION_SERVICE);
Location location =
locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null && Geocoder.isPresent()) {
Geocoder gcd = new Geocoder(current, Locale.getDefault());
List<Address> addresses;
addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses != null && !addresses.isEmpty()) {
Address address = addresses.get(0);
return address.getCountryCode();
}
}
return null;
}
示例7: U3DGamesClient
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public U3DGamesClient(ConnectionCallbacks connectionCallbacks) {
activity = UnityPlayer.currentActivity;
this.connectionCallbacks = connectionCallbacks;
playServicesSupported =
GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
if (playServicesSupported == ConnectionResult.SUCCESS) {
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(activity).
addApi(Games.API).addScope(Games.SCOPE_GAMES).
addConnectionCallbacks(gpscCallbacks).
addOnConnectionFailedListener(connectionFailedListener);
client = builder.build();
} else {
client = null;
}
id = System.currentTimeMillis();
StaticData.clients.put(id, this);
}
示例8: createServiceClient
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public static void createServiceClient() {
if (service == null) {
final Activity activity = UnityPlayer.currentActivity;
if (!activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
return;
}
service = new BCLServiceClient(activity);
((BCLServiceBase) service).addListener(instance);
}
}
示例9: createServiceServer
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public static void createServiceServer() {
if (service == null) {
final Activity activity = UnityPlayer.currentActivity;
if (!activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)) {
return;
}
service = new BCLServiceServer(activity);
((BCLServiceBase) service).addListener(instance);
}
}
示例10: createServiceCentral
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public static void createServiceCentral() {
if (service == null) {
final Activity activity = UnityPlayer.currentActivity;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("This app needs location access");
builder.setMessage("Please grant location access so this app can detect beacons.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener()
{
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onDismiss(DialogInterface dialog) {
activity.requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
}
});
builder.show();
}
});
}
}
if (!activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
return;
}
service = new BLEServiceCentral(activity);
((BLEServiceCentral)service).addListener(instance);
}
}
示例11: createServicePeripheral
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public static void createServicePeripheral() {
if (service == null) {
final Activity activity = UnityPlayer.currentActivity;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle("This app needs location access");
builder.setMessage("Please grant location access so this app can detect beacons.");
builder.setPositiveButton(android.R.string.ok, null);
builder.setOnDismissListener(new DialogInterface.OnDismissListener()
{
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onDismiss(DialogInterface dialog) {
activity.requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_REQUEST_COARSE_LOCATION);
}
});
builder.show();
}
});
}
}
if (!activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
return;
}
service = new BLEServicePeripheral(activity);
((BLEServicePeripheral)service).addListener(instance);
}
}
示例12: getPackageInfo
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
private static PackageInfo getPackageInfo() {
Activity activity = UnityPlayer.currentActivity;
PackageInfo packageInfo = null;
try {
packageInfo = activity.getPackageManager().getPackageInfo(activity.getPackageName(), PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
Log.e("BundleVersionManager", "packageInfo load error");
}
return packageInfo;
}
示例13: showToast
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public void showToast(final String str) {
final Activity activity = UnityPlayer.currentActivity;
// Show toast
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(activity, str, Toast.LENGTH_LONG).show();
}
});
}
示例14: SetNotification
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
public static void SetNotification(int id, long delayMs, String title, String message, String ticker, int sound, String soundName, int vibrate,
int lights, String largeIconResource, String smallIconResource, int bgColor, String bundle, String channel,
ArrayList<NotificationAction> actions)
{
Activity currentActivity = UnityPlayer.currentActivity;
AlarmManager am = (AlarmManager)currentActivity.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(currentActivity, UnityNotificationManager.class);
intent.putExtra("ticker", ticker);
intent.putExtra("title", title);
intent.putExtra("message", message);
intent.putExtra("id", id);
intent.putExtra("color", bgColor);
intent.putExtra("sound", sound == 1);
intent.putExtra("soundName", soundName);
intent.putExtra("vibrate", vibrate == 1);
intent.putExtra("lights", lights == 1);
intent.putExtra("l_icon", largeIconResource);
intent.putExtra("s_icon", smallIconResource);
intent.putExtra("bundle", bundle);
intent.putExtra("channel", channel);
Bundle b = new Bundle();
b.putParcelableArrayList("actions", actions);
intent.putExtra("actionsBundle", b);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
am.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + delayMs, PendingIntent.getBroadcast(currentActivity, id, intent, PendingIntent.FLAG_UPDATE_CURRENT));
else
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + delayMs, PendingIntent.getBroadcast(currentActivity, id, intent, PendingIntent.FLAG_UPDATE_CURRENT));
}
示例15: buildActionIntent
import com.unity3d.player.UnityPlayer; //导入方法依赖的package包/类
private static PendingIntent buildActionIntent(NotificationAction action, int id) {
Activity currentActivity = UnityPlayer.currentActivity;
Intent intent = new Intent(currentActivity, UnityNotificationActionHandler.class);
intent.putExtra("id", id);
intent.putExtra("gameObject", action.getGameObject());
intent.putExtra("handlerMethod", action.getHandlerMethod());
intent.putExtra("actionId", action.getIdentifier());
intent.putExtra("foreground", action.isForeground());
return PendingIntent.getBroadcast(currentActivity, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}