当前位置: 首页>>代码示例>>Java>>正文


Java UnityPlayer.currentActivity方法代码示例

本文整理汇总了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);
}
 
开发者ID:sanukin39,项目名称:UniLocalNotification,代码行数:20,代码来源:NotificationSender.java

示例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);
}
 
开发者ID:tenjikinc,项目名称:AndroidUnityPlugin,代码行数:34,代码来源:NotificationUtil.java

示例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);
}
 
开发者ID:Agasper,项目名称:unity-android-sharing-plugin,代码行数:23,代码来源:Sharing.java

示例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());
}
 
开发者ID:mizoguche,项目名称:UnitySimpleNotifier,代码行数:38,代码来源:SimpleNotificationService.java

示例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));
}
 
开发者ID:Agasper,项目名称:unity-android-notifications,代码行数:25,代码来源:UnityNotificationManager.java

示例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;
}
 
开发者ID:tinylabproductions,项目名称:tlplib,代码行数:20,代码来源:Bridge.java

示例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);
}
 
开发者ID:tinylabproductions,项目名称:u3d_gps_bridge,代码行数:21,代码来源:U3DGamesClient.java

示例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);
    }
}
 
开发者ID:seiji,项目名称:unity-bluetooth,代码行数:11,代码来源:BCLService.java

示例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);
    }
}
 
开发者ID:seiji,项目名称:unity-bluetooth,代码行数:11,代码来源:BCLService.java

示例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);
    }
}
 
开发者ID:seiji,项目名称:unity-bluetooth,代码行数:34,代码来源:BLEService.java

示例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);
    }
}
 
开发者ID:seiji,项目名称:unity-bluetooth,代码行数:34,代码来源:BLEService.java

示例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;
}
 
开发者ID:tenjikinc,项目名称:AndroidUnityPlugin,代码行数:13,代码来源:PackageInfoUtil.java

示例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();
            }
        });
    }
 
开发者ID:progmind,项目名称:HVC-C1B_Unity_Android_Plugin,代码行数:13,代码来源:MainActivity.java

示例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));
}
 
开发者ID:Agasper,项目名称:unity-android-notifications,代码行数:29,代码来源:UnityNotificationManager.java

示例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);
}
 
开发者ID:Agasper,项目名称:unity-android-notifications,代码行数:11,代码来源:UnityNotificationManager.java


注:本文中的com.unity3d.player.UnityPlayer.currentActivity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。