Java Code Examples for io.flutter.plugin.common.MethodChannel.Result#success()

The following examples show how to use io.flutter.plugin.common.MethodChannel.Result#success() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 6 votes vote down vote up
private void deleteConversation(MethodCall call, Result result) {
  HashMap<String, Object> map = call.arguments();
  try {
    JSONObject params = new JSONObject(map);
    String type = params.getString("type");

    if (type.equals("single")) {
      String username = params.getString("username");

      if (params.has("appKey") && !TextUtils.isEmpty(params.getString("appKey"))) {
        JMessageClient.deleteSingleConversation(username, params.getString("appKey"));
      } else {
        JMessageClient.deleteSingleConversation(username);
      }

    } else if (type.equals("group")) {
      long groupId = Long.parseLong(params.getString("groupId"));
      JMessageClient.deleteGroupConversation(groupId);

    } else if (type.equals("chatRoom")) {
      long roomId = Long.parseLong(params.getString("roomId"));
      JMessageClient.deleteChatRoomConversation(roomId);

    } else {
      handleResult(ERR_CODE_PARAMETER, "Conversation type is error", result);
      return;
    }

    result.success(null);
  } catch (JSONException e) {
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
  }
}
 
Example 2
Source File: BackgroundLocationUpdatesPlugin.java    From background_location_updates with Apache License 2.0 5 votes vote down vote up
private void markLocationTracesAsRead(MethodCall call, Result result) {
  List<?> arguments = (List<?>) call.arguments;
  List<List<Integer>> locationIds = Utils.chopIntoParts((List<Integer>) arguments.get(0), 900);
  for (List<Integer> chunk: locationIds) {
      new MarkAsReadTask(mContext).execute(chunk.toArray(new Integer[chunk.size()]));
  }
  result.success(0);
}
 
Example 3
Source File: FlutterUmplusPlugin.java    From flutter_umplus with MIT License 5 votes vote down vote up
private void initSetup(MethodCall call, Result result) {
    String appKey = (String)call.argument("key");
    String channel = (String)call.argument("channel");
    Boolean logEnable = (Boolean)call.argument("logEnable");
    Boolean encrypt = (Boolean)call.argument("encrypt");
    Boolean reportCrash = (Boolean)call.argument("reportCrash");

    Log.d("UM", "initSetup: " + appKey);
//    Log.d("UM", "channel: " +  getMetadata(activity, "INSTALL_CHANNEL"));

    UMConfigure.setLogEnabled(logEnable);
    UMConfigure.init(activity, appKey, channel, UMConfigure.DEVICE_TYPE_PHONE,
                     null);
    UMConfigure.setEncryptEnabled(encrypt);

    MobclickAgent.setSessionContinueMillis(30000L);
    MobclickAgent.setCatchUncaughtExceptions(reportCrash);

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      // 大于等于4.4选用AUTO页面采集模式
      MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
    } else {
      MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL);
    }


    result.success(true);
  }
 
Example 4
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void getMyInfo(MethodCall call, Result result) {
  UserInfo myInfo = JMessageClient.getMyInfo();
  if (myInfo != null) {
    result.success(toJson(myInfo));
  } else {
  // TODO:
    result.success(null);
  }
}
 
Example 5
Source File: ContactsServicePlugin.java    From flutter_contacts with MIT License 5 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, Result result) {
  switch(call.method){
    case "getContacts":
      this.getContacts((String)call.argument("query"), (boolean)call.argument("withThumbnails"), (boolean)call.argument("photoHighResolution"), result);
      break;
    case "getContactsForPhone":
      this.getContactsForPhone((String)call.argument("phone"), (boolean)call.argument("withThumbnails"), (boolean)call.argument("photoHighResolution"), result);
      break;
    case "addContact":
      Contact c = Contact.fromMap((HashMap)call.arguments);
      if(this.addContact(c)) {
        result.success(null);
      } else{
        result.error(null, "Failed to add the contact", null);
      }
      break;
    case "deleteContact":
      Contact ct = Contact.fromMap((HashMap)call.arguments);
      if(this.deleteContact(ct)){
        result.success(null);
      } else{
        result.error(null, "Failed to delete the contact, make sure it has a valid identifier", null);
      }
      break;
    case "updateContact":
      Contact ct1 = Contact.fromMap((HashMap)call.arguments);
      if(this.updateContact(ct1)) {
        result.success(null);
      } else {
        result.error(null, "Failed to update the contact, make sure it has a valid identifier", null);
      }
      break;
    default:
      result.notImplemented();
      break;
  }
}
 
Example 6
Source File: FlutterUmengAnalyticsPlugin.java    From flutter_umeng_analytics with MIT License 5 votes vote down vote up
public void init(MethodCall call, Result result) {
    // 设置组件化的Log开关,参数默认为false,如需查看LOG设置为true
    UMConfigure.setLogEnabled(true);
    /**
     * 初始化common库 参数1:上下文,不能为空 参数2:【友盟+】Appkey名称 参数3:【友盟+】Channel名称
     * 参数4:设备类型,UMConfigure.DEVICE_TYPE_PHONE为手机、UMConfigure.DEVICE_TYPE_BOX为盒子,默认为手机
     * 参数5:Push推送业务的secret
     */
    UMConfigure.init(activity, (String) call.argument("key"), "Umeng", UMConfigure.DEVICE_TYPE_PHONE, null);
    // 设置日志加密 参数:boolean 默认为false(不加密)
    UMConfigure.setEncryptEnabled((Boolean) call.argument("encrypt"));

    double interval = call.argument("interval");
    if (call.argument("interval") != null) {
        // Session间隔时长,单位是毫秒,默认Session间隔时间是30秒,一般情况下不用修改此值
        MobclickAgent.setSessionContinueMillis(Double.valueOf(interval).longValue());
    } else {
        // Session间隔时长,单位是毫秒,默认Session间隔时间是30秒,一般情况下不用修改此值
        MobclickAgent.setSessionContinueMillis(30000L);
    }


    // true表示打开错误统计功能,false表示关闭 默认为打开
    MobclickAgent.setCatchUncaughtExceptions((Boolean) call.argument("reportCrash"));

    // 页面采集的两种模式:AUTO和MANUAL,Android 4.0及以上版本使用AUTO,4.0以下使用MANUAL
    int results = call.argument("mode");
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (results == 0) {
            // 大于等于4.4选用AUTO页面采集模式
            MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
        }
    } else if (results == 1) {
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL);
    }
    result.success(true);
}
 
Example 7
Source File: FlutterFlipperkitPlugin.java    From flutter_flipperkit with MIT License 5 votes vote down vote up
private void clientAddPlugin(MethodCall call, Result result) {
    if (call.hasArgument("id")) {
        final String pluginId = call.argument("id");
        if (pluginId == null) {
            result.error("", "", "");
            return;
        }
        // 当插件已经添加时,避免再次添加
        if (flipperClient.getPlugin(pluginId) != null) {
            result.success(true);
            return;
        }
        switch (pluginId) {
            case NetworkFlipperPlugin.ID:
                flipperClient.addPlugin(networkFlipperPlugin);
                break;
            case "Preferences":
                flipperClient.addPlugin(sharedPreferencesFlipperPlugin);
                break;
            case FlipperDatabaseBrowserPlugin.ID:
                flipperClient.addPlugin(flipperDatabaseBrowserPlugin);
                break;
            case FlipperReduxInspectorPlugin.ID:
                flipperClient.addPlugin(flipperReduxInspectorPlugin);
                break;
        }
    }

    result.success(true);
}
 
Example 8
Source File: AmapLocationPlugin.java    From location_plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void onMethodCall(MethodCall call, Result result) {
	if (call.method.equals("startLocation")) {
		//启动定位
		mLocationClient.startLocation();
	} else if (call.method.equals("stopLocation")) {
		//停止定位
		mLocationClient.stopLocation();
	} else if (call.method.equals("getLocation")) {
		result.success(mLocation);
	} else {
		result.notImplemented();
	}
}
 
Example 9
Source File: FlutterPdfActivity.java    From pspdfkit-flutter with Apache License 2.0 5 votes vote down vote up
private void releaseActivity() {
    Result result = loadedDocumentResult.getAndSet(null);
    if (result != null) {
        result.success(false);
    }
    currentActivity = null;
}
 
Example 10
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 5 votes vote down vote up
/**
 * This is a network that does not broadcast its SSID, so an
 * SSID-specific probe request must be used for scans.
 */
private void isSSIDHidden(Result poResult) {
    WifiConfiguration oWiFiConfig = moWiFiAPManager.getWifiApConfiguration();
    if (oWiFiConfig != null && oWiFiConfig.hiddenSSID) {
        poResult.success(oWiFiConfig.hiddenSSID);
        return;
    }
    poResult.error("Exception", "Wifi AP not Supported", null);
}
 
Example 11
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 5 votes vote down vote up
private void deleteMessageById(MethodCall call, Result result) {
  HashMap<String, Object> map = call.arguments();
  Conversation conversation;
  String messageId;

  try {
    JSONObject params = new JSONObject(map);

    conversation = JMessageUtils.getConversation(params);

    if (conversation == null) {
      handleResult(ERR_CODE_CONVERSATION, "Can't get conversation", result);
      return;
    }

    messageId = params.getString("messageId");
  } catch (JSONException e) {
    e.printStackTrace();
    handleResult(ERR_CODE_PARAMETER, ERR_MSG_PARAMETER, result);
    return;
  }

  boolean success = conversation.deleteMessage(Integer.parseInt(messageId));

  if (success) {
    result.success(null);
  } else {
    HashMap error = new HashMap();
    error.put("code", ERR_CODE_MESSAGE);
    error.put("description", ERR_MSG_MESSAGE);
    result.error(ERR_CODE_MESSAGE + "", ERR_MSG_MESSAGE, "");
  }
}
 
Example 12
Source File: BackgroundLocationUpdatesPlugin.java    From background_location_updates with Apache License 2.0 5 votes vote down vote up
private void startTrackingWithPeriodicStrategy(MethodCall call, Result result) {
  Integer requestInterval = extractAndPersistRequestInterval(call);
  locationTrackingStarted(requestInterval);
  PeriodicLocationTracker.stopLocationTracking();
  PeriodicLocationTracker.scheduleLocationTracking(requestInterval);
  result.success(true);
}
 
Example 13
Source File: RazorpayDelegate.java    From razorpay-flutter with MIT License 4 votes vote down vote up
public void resync(Result result) {
    result.success(pendingReply);
    pendingReply = null;
}
 
Example 14
Source File: JmessageFlutterPlugin.java    From jmessage-flutter-plugin with MIT License 4 votes vote down vote up
private void getAllUnreadCount(MethodCall call, Result result) {
  int count = JMessageClient.getAllUnReadMsgCount();
  result.success(count);
}
 
Example 15
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 4 votes vote down vote up
private void isEnabled(Result poResult) {
    poResult.success(moWiFi.isWifiEnabled());
}
 
Example 16
Source File: FlutterFlipperkitPlugin.java    From flutter_flipperkit with MIT License 4 votes vote down vote up
private void clientStart(MethodCall call, Result result) {
    flipperClient.start();

    result.success(true);
}
 
Example 17
Source File: AuthorizeModule.java    From reader-sdk-flutter-plugin with Apache License 2.0 4 votes vote down vote up
public void canDeauthorize(Result flutterResult) {
  flutterResult.success(ReaderSdk.authorizationManager().getAuthorizationState().canDeauthorize());
}
 
Example 18
Source File: FastQrReaderViewPlugin.java    From fast_qr_reader_view with MIT License 4 votes vote down vote up
void stopScanning(@NonNull Result result) {
    stopScanning();
    result.success(null);
}
 
Example 19
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 3 votes vote down vote up
private void setWiFiAPSSID(MethodCall poCall, Result poResult) {
    String sAPSSID = poCall.argument("ssid");

    WifiConfiguration oWiFiConfig = moWiFiAPManager.getWifiApConfiguration();

    oWiFiConfig.SSID = sAPSSID;

    moWiFiAPManager.setWifiApConfiguration(oWiFiConfig);

    poResult.success(null);
}
 
Example 20
Source File: WifiIotPlugin.java    From WiFiFlutter with MIT License 2 votes vote down vote up
/**
 * Return whether Wi-Fi AP is enabled or disabled.
 * *** isWifiApEnabled :
 * return {@code true} if Wi-Fi AP is enabled
 */
private void isWiFiAPEnabled(Result poResult) {
    poResult.success(moWiFiAPManager.isWifiApEnabled());
}